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

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;



人生于世,就得有点兴致,闲暇之时,或乐游山水、或尽享食味、或寄情岁时,它让我们的生活变得充盈。

评论

^