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;