我有一个每1小时不同位置的测量数据库。
ID | LOCATION_ID | CMS | DATE
6 | C | 7 | 2014-11-27 12:00:00
5 | B | 3 | 2014-11-27 12:00:00
4 | A | 19 | 2014-11-27 12:00:00
3 | C | 9 | 2014-11-27 11:00:00
2 | B | 8 | 2014-11-27 11:00:00
1 | A | 11 | 2014-11-27 11:00:00
我需要在过去3小时内为每个唯一身份选择最高cms
。例如;
ID | LOCATION_ID | CMS | DATE
3 | C | 9 | 2014-11-27 11:00:00
2 | B | 8 | 2014-11-27 11:00:00
4 | A | 19 | 2014-11-27 12:00:00
我使用下面的MySQL来返回最大值,但我错过了最后一块。我需要什么来完成声明?
SELECT MAX(cms) as value_of_rain
FROM `rainfall`
WHERE `date` >= SUBDATE( NOW( ) , INTERVAL 3 HOUR )
答案 0 :(得分:1)
您正在使用GROUP BY
SELECT MAX(cms) as value_of_rain
FROM `rainfall`
WHERE `date` >= SUBDATE( NOW( ) , INTERVAL 10 MINUTE )
GROUP BY LOCATION_ID