天天看点

Sql 中null值对常用函数的影响

null  需要使用 is  null   或者  is  not  null  进行判断

distinct 会将所有null视为一项

group by 将所有null值视为一项

count(*/1)包括null值,count(columnName)不会计算null值

max()  min()  sum()  avg() 都会忽略null值

not in 或者   in 在进行计算时,使用 = 号判断值是否相等,遇到null值时需要注意。

eg.  select 'yes' from  table_tmp   where column_test not in/in (1,2,3,null)  limit  1

当  null  等于 column_test时,sql会执行完成,但没有任何返回值.

当null值出现在(list)中时,in可以正常使用,因为只要有一个值满足=条件就可以,null值是否存在没有影响,

                                         not in 要求所有值都满足!=条件,而null值无法依靠=条件判断,所以结果会异常。