select user,sum(num) as total from tb group by user order by total desc 试试