create table t(_user char(1),num int) insert t select 'a',1 union all select 'b',4 union all select 'c',3 union all select 'b',2 union all select 'c',2select _user,sum(num) [sum] from t group by _user order by sum descdrop table t /* _user sum ----- ----------- b 6 c 5 a 1 */
insert t select 'a',1
union all select 'b',4
union all select 'c',3
union all select 'b',2
union all select 'c',2select _user,sum(num) [sum] from t
group by _user
order by sum descdrop table t
/*
_user sum
----- -----------
b 6
c 5
a 1
*/