Hello All,
I am asking whether there is a better way to write below query or not.Or could you give me some advices make it perform well ?
select id_emp,amount from ( select id_emp,event_month,amount,ROW_NUMBER () over ( partition by id_emp order by event_month desc ) rn from ( select id_emp,event_month,SUM(amount) amount from Table_X where 1 = 1 and id_emp = @id_emp and group_type = @group_type group by id_emp,event_month ) sub ) sub where sub.rn = 1