我有一张类似
的表格phoneNumber | City | totalPoints
12345678 | Singapore | 2000
12345679 | Singapore | 3000
23456789 | New York | 2100
12312312 | New York | 2200
12312343 | Beijing | 4000
我希望得到像
这样的结果phoneNumber | City | totalPoints
12345679 | Singapore | 3000
12312312 | New York | 2200
12312343 | Beijing | 4000
只需选择每个城市中totalPoints最大值的行。如何编写SQL代码? (我正在使用MS SQL Server)
答案 0 :(得分:3)
在sql-server中:
select * from
(
select *,rn=row_number()over(partition by City order by totalpoints desc) from table
)x
where rn=1