22,301
社区成员




declare @table table (id int,score int)
insert into @table
select 1,60 union all
select 2,70 union all
select 3,70 union all
select 1,45 union all
select 5,24 union all
select 2,80 union all
select 4,88 union all
select 1,70
select id,sum(score) as sumscore
from @table group by id
order by sum(score) desc
/*
id sumscore
----------- -----------
1 175
2 150
4 88
3 70
5 24
*/
select * from (select id,sum(score) as score
from table
group by id) t
order by score desc