如何在所有日期获得结果?

时间:2011-06-02 16:10:10

标签: sql date phpmyadmin

在此查询中,我只获得WET> = 6的日期值。这些天我怎么能得到'0'?

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)

1 个答案:

答案 0 :(得分:0)

正如我现在所理解的那样,当没有WET >= 6的记录时,你想要返回一个默认值。您可以使用此处描述的技术完成此操作:

Oracle: Get a query to always return exactly one row, even when there's no data to be found