I have a log table in SQL Server. Table is structured this way:
Unique ProblemID ResponsibleID AssignedToID ProblemCode
155 155 0282 4
156 155 0900
157 155 3
158 155 0147 1
159 159 0111 2
160 159 0333 4
161 159 0900 1
So basically we log all problems and who was responsible/had to deal with the problem. I need a query that would find which problems one person was involved in:
For example:
- Person with ID 0900 was involved in both 155 and 159.
- Person with ID 0282 was involved in 155 only.
- Person with ID 0333 was involved in 159 only.
Also I forgot to mention that I need to filter the last row of ProblemID by the ProblemCode. For example find problemID where person is involved, but there the ProblemCode in the last log line of that problem is 1 (Which means the problem is now closed).
Furthermore, I was working with query:
select ProblemID, EntryTime, ResponsibleID, ProblemCode, AssignedToID
from (select ProblemID, EntryTime, ResponsibleID, ProblemCode, AssignedToID,
row_number() over(partition by ProblemID order by EntryTime desc) as rn
from myTable) as T
where rn = 1 and ResponsibleID = 00282 OR AssignedToID = 00282
and veiksmoid <> 4
However, it ONLY matches the last rows.