日期:2014-05-18 浏览次数:20595 次
SELECT Row_Number OVER (ORDER BY 成绩 DESC) AS Num , 用户名 FROM 成绩表 GROUP BY 用户名
--> 测试数据:[test]
if object_id('[test]') is not null drop table [test]
create table [test]([主键ID] int,[用户名] varchar(4),[成绩] int,[日期] datetime)
insert [test]
select 1,'张三',500,'2012-01-01' union all
select 2,'张三',400,'2012-01-02' union all
select 3,'李四',100,'2012-01-04' union all
select 4,'李四',200,'2012-01-05'
select * from [test] a
where a.成绩=(select max(成绩) from [test] b where a.用户名=b.用户名)
/*
主键ID 用户名 成绩 日期
-------------------------------------------------
1 张三 500 2012-01-01 00:00:00.000
4 李四 200 2012-01-05 00:00:00.000
*/
------解决方案--------------------