选择每个组具有最高日期的记录

时间:2016-06-03 11:25:50

标签: mysql

我有一个这种类型的表:

table : people
+-------+-----------+-----------+-------------------+
|   id  |   name    |   amount  |       date        |
+-------+-----------+-----------+-------------------+
|   1   |   John    |      12   |    2011-12-03     |
|   2   |   John    |       7   |    2016-02-01     |
|   3   |   Mary    |       0   |    2014-06-23     |
|   4   |   John    |       7   |    2016-01-01     |
|   4   |   Mary    |       5   |    2014-06-01     |
|   4   |   Bill    |       1   |    2010-08-14     |
+-------+-----------+-----------+-------------------+

我需要编写一个查询来选择每个名称具有最高日期的记录。

结果将是:

+-----------+-----------+-------------------+
|   name    |   amount  |       date        |
+-----------+-----------+-------------------+
|   John    |       7   |    2016-02-01     |
|   Mary    |       0   |    2014-06-23     |
|   Bill    |       1   |    2010-08-14     |
+-----------+-----------+-------------------+

0 个答案:

没有答案