【发布时间】:2021-07-30 12:15:11
【问题描述】:
我有一张表people,其中包含人们、他们的城市和他们的资金余额:
id city_id money
1 1 25
2 1 13
3 2 97
4 2 102
5 2 37
现在,我想从每个城市中选出最富有的人。如何使用 Oracle SQL 做到这一点?期望的结果是:
id city_id money
1 1 25
4 2 102
类似的东西会很有用:
SELECT * as tmp FROM people GROUP BY city_id HAVING money = MAX(money)
【问题讨论】:
标签: sql oracle group-by oracle11g greatest-n-per-group