我遇到此查询的问题。它应返回当天的最高温度但返回空。我做错了什么?
SELECT * 来自tempdat WHERE日期(tdate)= curdate() 和温度=( SELECT max(温度) 来自tempdat);
答案 0 :(得分:0)
您的子查询返回数据的总体最大值 - 而不是当天,您需要以下内容:
select max(temperature) from tempdat group by tdate having tdate = curdate()
答案 1 :(得分:0)
而是使用:
SELECT
convert(datetime, convert(varchar(12), tdate )) AS DayOfTemp
,max(temperature) AS MaxTemp
FROM
tempdat
WHERE
convert(datetime, convert(varchar(12), tdate )) = convert(datetime, convert(varchar(12, curdate( ) ))
group by
convert(datetime, convert(varchar(12), tdate ))