如何获取忽略NULL和零值的列的AVG?
我有三列可以得到他们的平均值,我尝试使用以下脚本:
SELECT distinct
AVG(cast(ISNULL(a.SecurityW,0) as bigint)) as Average1
,AVG(cast(ISNULL(a.TransferW,0) as bigint)) as Average2
,AVG(cast(ISNULL(a.StaffW,0) as bigint)) as Average3
FROM Table1 a, Table2 b
WHERE a.SecurityW <> 0 AND a.SecurityW IS NOT NULL
AND a.TransferW<> 0 AND a.TransferWIS NOT NULL
AND a.StaffW<> 0 AND a.StaffWIS NOT NULL
AND MONTH(a.ActualTime) = 4
AND YEAR(a.ActualTime) = 2013
我没有得到任何结果,但是这三列的值包括NULL和零!
有没有排除空值获得平均值之前?
示例:AVERAGE(NOTNULL(SecurityW))