select t.id, t.name, t.grade_sum
from
(select u.id,u.name,
sum(g.grade_num * case when type = 'add' then 1 else -1 end) as grade_sum,
dense_rank() over(order by sum(g.grade_num * case when type = 'add' then 1 else -1 end) desc) as idx
from user u, grade_info g
where u.id = g.user_id
group by u.id, u.name) t
where t.idx = 1