抱歉我的描述不好,但我正在尝试获取最后吃每种水果的每个人的最新日期。我认为我的分组不正确,或者我完全错过了一些东西。有人可以帮我弄这个吗?提前致谢。
T1
+--------+--------+--------+
| person | fruit | date |
+--------+--------+--------+
| Bob | apple | 1-1-13 |
| Bob | apple | 1-4-13 |
| Bob | apple | 1-6-13 |
| Bob | orange | 1-2-13 |
| John | apple | 1-3-13 |
| John | orange | 1-2-13 |
| John | orange | 1-4-13 |
| John | orange | 1-9-13 |
+--------+--------+--------+
Results I'm looking for
+--------+--------+--------+
| person | fruit | date |
+--------+--------+--------+
| Bob | apple | 1-6-13 |
| Bob | orange | 1-2-13 |
| John | apple | 1-3-13 |
| John | orange | 1-9-13 |
+--------+--------+--------+
我从阅读类似帖子中得到的尝试。
SELECT * FROM T1
JOIN (
SELECT person,max(date) AS latest
FROM T1 GROUP BY person
) T2
ON T1.person = T2.person AND T1.date = T2.latest
Resulting in
+--------+--------+--------+
| person | fruit | date |
+--------+--------+--------+
| Bob | apple | 1-6-13 |
| John | orange | 1-9-13 |
+--------+--------+--------+
我如何让它也分离水果柱?