avg()传回选取的结果集中值的平均值。已忽略 Null 值,但是如果符合条件的集合里面全部为null,那么返回null
例如集合只有一个栏位:
表格:test_null
sno
null(没有其他纪录)那么select avg(sno),avg(isnull(sno,0)) from test_null                      
----------- ----------- 
NULL        0Warning: Null value is eliminated by an aggregate or other SET operation.表格:test_null
sno
null

那么执行select avg(sno),avg(isnull(sno,0)) from test_null                        
----------- ----------- 
2           1Warning: Null value is eliminated by an aggregate or other SET operation.
--只是avg(sno),那么为null的會被忽略掉,因此平均值為2,如果為Null替換為0,就是1好像我自己本也有點模糊~
不过记住这点:对集合函数来说,如果空值可能导致错误结果,ISNULL函数就非常有用