我遇到以下代码问题。我希望它从特定区域返回最大温度。区域有几个。我想两组之间的AND
都是错误的。
select max(temperature)
from tempdat
group by tdate having tdate = curdate()
and group having zone having zone ='inne'
数据库有4个列,此查询只返回温度列,如何获取结果中的所有列?
答案 0 :(得分:0)
select t1.zone_id,t1.temperature
from tempdat t1
where
t1.tdate = curdate()
and t1.temperature =
(select max(t2.temperature) from tempdat t2
where t1.tdate = t2.tdate
and t1.zone_id = t2.zone_id);
答案 1 :(得分:0)
每个日期的最大值 -
select max(temperature), tdate,zone
from tempdat
group by tdate, zone
如果您想要特定区域,请尝试每个日期
select max(temperature), tdate,zone
from tempdat where zone ='inne'
group by tdate, zone
如果你想要每个区域的最大值和curr_date,
select max(temperature),zone
from tempdat
where tdate = curdate()
group by zone
如果要应用过滤器,最好在WHERE子句中而不是在HAVING子句中应用它们。只有当您想对聚合数据应用过滤器时,才需要将它们放在HAVING子句中。