我怎样才能得到所有日期的结果?
在此查询中,我仅获取 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)
On this query, I only get values on the days where WET>=6. How can I 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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我现在的理解,当没有
WET >= 6
的记录时,您希望返回默认值。您可以使用此处描述的技术来完成此操作:Oracle:即使没有找到数据,查询也始终只返回一行
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