I have the below query -
select w1.System_Id, w1.TeamProjectSK, w1.System_State, w1.System_Rev
from dbo.DimWorkItem w1
where w1.System_Id = 29259
order by w1.TeamProjectSK asc, w1.System_Rev desc
The output looks like -
System_Id TeamProjectSK System_State System_Rev
29259 4 Closed 6
29259 4 Resolved 5
29259 4 Active 4
29259 4 Active 3
29259 4 Active 2
29259 4 Proposed 1
Now, i need my output to look like -
System_Id TeamProjectSK System_State System_Rev
29259 4 Closed 6
29259 4 Resolved 5
29259 4 Active 4
29259 4 Proposed 1
That is, I want to have the highest value in the "System_Rev" column grouped by "System_State". I tried the below query -
select w1.System_Id, w1.TeamProjectSK, w1.System_State, w1.System_Rev
from dbo.DimWorkItem w1
inner join
(
select System_State, max(System_Rev) as m
from dbo.DimWorkItem group by System_State
) w
on w1.System_State = w.System_State and w1.System_Rev = w.m
order by w1.System_Id asc, w1.TeamProjectSK asc
But it didn't work to my benefit. Please help.
Regards.