数据运算null的处理

1.null在数据库的运算中并不等同于0

2.任何数与null参与运算后,其结果都为null

 

为了让null能起到0的效果,使用一个语句IFNULL来进行实现:

代码如下:

1 select salary * (1 + commission_pct) "月工资",commission_pct -- 所有commision_pct为null的得到的月工资的值均为null
2 from employees;
3 
4 select salary * (1 + ifnull(commission_pct,0)) "月工资",commission_pct -- 将得到的null作为0处理
5 from  employees; 

 

posted @ 2022-03-13 11:24  jue1e0  阅读(197)  评论(0)    收藏  举报