sql script
select u.id, u.name, tmp1.grade_sum from (select user_id, rank() over(order by grade_sum desc) as g_rank, grade_sum from (select user_id, sum(if(type='add',1,-1)*grade_num) as grade_sum from grade_info group by user_id) tmp) tmp1, `user` u where tmp1.user_id=u.id and tmp1.g_rank=1