MySQL常用的单行函数汇总4——流程控制函数
作者:互联网
1.IF函数:
IF(condition,value1,value2):如果condition条件成立,则返回value1的值,如果condition条件不成立,则返回value2的值
实例:
1 SELECT last_name,salary,IF(salary >= 6000,'高工资','低工资') "details" 2 FROM employees; 3 4 SELECT last_name,commission_pct,IF(commission_pct IS NOT NULL,commission_pct,0) "details", 5 salary * 12 * (1 + IF(commission_pct IS NOT NULL,commission_pct,0)) "annual_sal" 6 FROM employees;
2.IFNULL函数:
IFNULL(property,value1,value2):如果property为null,则返回value1的值,如果property不为null,则返回value2的值
实例:
1 SELECT last_name,commission_pct,IFNULL(commission_pct,0) "details" 2 FROM employees;
标签:函数,commission,pct,单行,value2,value1,MySQL,SELECT,details 来源: https://www.cnblogs.com/jue1e0/p/16083751.html