How can I get result on all dates?
On this query, I only get values on the days where WET>=6. How can I 开发者_JAVA百科get ´0´ on these days?
SELECT
DATE(DTM) AS 'Dia',
CASE
WHEN (AVG(TMP)<13 OR COUNT(WET)=0) THEN '0'
WHEN ((AVG(TMP)>=13 AND AVG(TMP)<17) AND (COUNT(TMP)/4>=0 AND COUNT(TMP)/4<6)) THEN '0'
WHEN ((AVG(TMP)>=13 AND AVG(TMP)<17) AND (COUNT(TMP)/4>=6 AND COUNT(TMP)/4<15)) THEN '1'
WHEN ((AVG(TMP)>=13 AND AVG(TMP)<17) AND (COUNT(TMP)/4>=15 AND COUNT(TMP)/4<20)) THEN '2'
WHEN ((AVG(TMP)>=13 AND AVG(TMP)<17) AND (COUNT(TMP)/4>=20)) THEN '3'
END
AS 'DSV TOMCAST'
FROM dados_meteo
WHERE WET>=6/* AND POM='[VARIABLE]'*/
GROUP BY DATE(DTM)
As I understand it now, you wanna return a default value when there's no record with WET >= 6
. You can accomplish this with the technique described here:
Oracle: Get a query to always return exactly one row, even when there's no data to be found
精彩评论