select id,name,sgn
from(select id,name,sgn,rank()over(order by sgn desc) rk
from(select user_id,sum(gn) sgn
from(select user_id,case when type='add' then grade_num else -grade_num end gn
from grade_info) t 
group by user_id) t1 left join user u on t1.user_id=u.id) t2
where rk=1
order by id

想要将某一列数值变为负数直接加负号即可