null值字段运算前先把null转成0
test表如下,num2为null
select num1-num2 from test;
结果为null
减去null值结果为null
select sum(num1),SUM(num2) from test ;
sum求和结果为null
判断字段是null不能用 =null ,要用is null
错误写法:
select IF(num1 = NULL,0,num1) from test ;
正确写法
select IF(num1 is NULL,0,num1) from test ;
或者
select IFNULL(num1,0) from test;