Code:
select sum(t1.Amount) as Amount
from tblTest as t1
where t1.KeyID = (select max(t2.KeyID)
from tblTest as t2
where t2.UserID = t1.UserID
);
Code:
;with cte as (
select KeyID, UserID, Amount,
row_number() over(partition by UserID order by KeyID desc) as RowNum
Leave a comment: