Mysql - 在查询结果中显示更多细节

时间:2016-11-29 19:06:08

标签: mysql sql

SELECT MIN(temperature) 
FROM temperature 
WHERE sensor_id = '28-0316387a1eff' 
AND DATE(`dtg`) = CURDATE()

这样可以显示当天的最低温度。 如何让它向我展示发生这种情况的时间?

dtg使用current_timestamp

谢谢。

2 个答案:

答案 0 :(得分:0)

您可以选择温度=最小(温度)的行

select `dtg`, temperature
from temperature
where temperature = (
    SELECT MIN(temperature) 
    FROM temperature 
    WHERE sensor_id = '28-0316387a1eff' 
    AND DATE(`dtg`) = CURDATE()
 )

答案 1 :(得分:0)

不使用子选择会更快。最好试试这个:

select t.dtg ,t.temperature
from temperature t
WHERE t.sensor_id = '28-0316387a1eff' 
AND DATE(t.dtg) = CURDATE()
order by t.temperature 
limit 1
相关问题