0
我有一列我可以得到0值,但我需要計算該列的平均值,而不計算這些0作爲分頻器的一部分。使AVG()忽略0的?
我有以下查詢:
SELECT AVG(CAST(RATING AS NUMERIC(18, 2))) AS AVERAGE,
QUESTIONID,
Questions.SHORTVERSION,
COUNT(CASE
WHEN RATING > 0
THEN 1
ELSE NULL
END) AS COUNT
FROM AnswersRating
INNER JOIN Questions ON Questions.ID = QUESTIONID
WHERE SURVEYID IN
(
SELECT ID
FROM SURVEYS
WHERE FLIGHTDATAID = '8371'
)
GROUP BY QUESTIONID,
Questions.SHORTVERSION
ORDER BY QUESTIONID;
我讀的地方,我可以用NULLIF
,以幫助這一點,但我無法弄清楚如何正確使用它。任何人都可以幫助我?
您可以使用NULLIF。 NULLIF(RATING,0) – VDK
你不可以添加'where rating> 0'嗎? –
我同意@vkp,其中your_col!= 0 – samirk433