#流程控制函数
#IF(VALUE,VALUE1,VALUE2)
SELECT last_name,salary,IF(salary>=6000,'高工资','低工资')
FROM employees;
SELECT last_name,commission_pct,IF(commission_pct IS NOT NULL,commission_pct,0)"details"
salary * 12 * (1 + IF(commission_pct IS NOT NULL,commission_pct,0)) "annual_sal"
FROM employees;
#IFNULL(VALUE1,VALUE2):看做是IF(VALUE,VALUE1,VALUE2)的特殊情况
SELECT last_name,commission_pct,IFNULL(commission_pct,0) "details"
FROM employees;
#CASE ...WHEN .... THEN....WHEN....THEN.....ELSE....END
SELECT last_name,salary,CASE WHEN salary >= 15000 THEN '白骨精'
WHEN salary >=10000 THEN '潜力股'
WHEN salary >=8000 THEN '小屌丝'
ELSE '草根'
END "details",department_id
FROM employees;
#CASE... WHEN .... THEN....WHEN....THEN.....ELSE....END
SELECT employee_id,last_name,department_id,salary,CASE department_id WHEN 10 THEN salary * 1.1
WHEN 20 THEN salary * 1.2
WHEN 30 THEN salary * 1.3
ELSE salary * 1.4 END "details"FROM employees ;
流程控制函数
最新推荐文章于 2023-04-21 12:01:22 发布