CASE WHEN和DECODE的用法

--10号部门的员工工资提升10%显示,20号提升20%,30号部门提升30%,其余部门不提升,工资重命名为
--update_salary
SELECT EMPLOYEE_ID,
DEPARTMENT_ID,
CASE DEPARTMENT_ID
WHEN 10 THEN
  1.1 * SALARY
WHEN 20 THEN
  1.2 * SALARY
WHEN 30 THEN
  1.3 * SALARY
ELSE
  SALARY
END "update_salary"
FROM EMPLOYEES

SELECT EMPLOYEE_ID,
DEPARTMENT_ID,
DECODE(DEPARTMENT_ID,
  10,
  1.1 * SALARY,
  20,
  1.2 * SALARY,
  30,
  1.3 * SALARY,
  SALARY) UPDATE_SALARY
FROM EMPLOYEES

decode():decode(字段名,条件1,执行内容1,条件2,执行内容2,条件3,执行内容3,默认执行内容)
相当于java中if(){}else if(){}else if(){}...else{}

posted @ 2019-02-26 22:16  程序员小明1024  阅读(303)  评论(0编辑  收藏  举报