如何获得AVG
忽略NULL
和零值的列?
我有三列来获得他们的平均值,我尝试使用以下脚本:
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))