计算机网络/计算机科学与应用/系统/运维/开发

MySQL8 空值参与运算:NULL

空值参与运算:NULL

null 不等同于0 '' 'null'


错误写法:空值参与运算,结果一定也为空

SELECT employee_id,salary "月工资",salary * (1+commission_pct) * 12 "年工资"

     FROM employees;


实际解决:引入IFNULL

SELECT employee_id,salary "月工资",salary * (1 + IFNULL(commission_pct,0)) * 12 "年工资"
     FROM employees;



知识是抵御一切灾祸的盾牌

评论

^