我有一张表,每小时都会给出每天的人口编号。如何获得最大人口数的行?这是表格的一个例子
date hour population
2015-07-11 10 205
2015-07-11 11 390
2015-07-11 12 579
2015-07-11 13 679
2015-07-11 14 699
2015-07-11 15 890
2015-07-11 16 816
2015-07-11 17 970
2015-07-11 18 835
2015-07-11 19 827
2015-07-11 20 753
2015-07-11 21 638
2015-07-11 22 327
2015-07-12 9 33
2015-07-12 10 151
2015-07-12 11 227
2015-07-12 12 419
2015-07-12 13 561
2015-07-12 14 683
2015-07-12 15 799
2015-07-12 16 830
2015-07-12 17 876
2015-07-12 18 844
2015-07-12 19 819
2015-07-12 20 626
2015-07-12 21 526
2015-07-12 22 235
答案 0 :(得分:1)
尝试使用MAX()获取每个列的最大值:
SELECT date, MAX(population)
FROM foo
GROUP BY date
编辑:
如果您希望获得与最大人口值相对应的小时,您可以使用:
SELECT foo.*
FROM foo
INNER JOIN
(SELECT date, MAX(population) as MaxPop
FROM foo
GROUP BY date) max
ON foo.date = max.date
AND foo.population = max.MaxPop
希望它有所帮助。