1、在聚合函數中NULL不參與計算
例如表tb 有四個字段 id a b c(id是自增id)
a | b | c |
NULL | NULL | 10 |
NULL | 10 | 20 |
select sum(a) from tb
--返回結果是NULL
select sum(b) from tb
--返回結果是10
select sum(c) from tb
--返回結果是30
count()不包括對null值的統計,可以用isnull函數進行轉換
select count(a) from tb
--返回結果是0
select count(b) from tb
--返回結果是1
select count(c) from tb
--返回結果是2
--所以如果用count查詢共多少行時,最好不要用字段值可能是NULL的字段
2、在加減乘除運算中,如果值是NULL,則返回NULL
select a + b from tb where id=2
--返回結果是NULL
3、<>或者!=或者=對null值是不起作用的
select * from tb where b <> 10
--返回結果是: 沒有符合條件的數據