TSQL - Average of all values in a column that are not zero

后端 未结 2 892
时光说笑
时光说笑 2020-12-16 11:40

I\'m in the process of writing a report and am looking to get the average value of an age column. The problem is that not all rows have an age.

If the values for the

2条回答
  •  别那么骄傲
    2020-12-16 11:49

    SELECT
    
        AVG (CASE WHEN Value <> 0 THEN Value ELSE NULL END)
        ....
    

    AVG won't take into account NULL values. Or this

        AVG (NULLIF(Value, 0))
    

提交回复
热议问题