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

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;



顺,不妄喜;逆,不惶馁;安,不奢逸;危,不惊惧。--史记

评论

^