我有一个在SQL Server中的日志表。该表结构如下:
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
所以基本上我们会记录下所有的问题和负责/需要处理该问题的人员。 我需要一个查询来查找某个人参与的问题:
例如:
- 编号为0900的人参与了155和159两个问题。
- 编号0282的人仅参与了155个问题。
- 编号0333的人仅参与了159个问题。
另外,我忘记提到我需要通过ProblemCode过滤最后一行ProblemID。例如,查找该人参与的问题ID,但是该问题的最后一行日志中的ProblemCode为1(这意味着该问题现已关闭)。
此外,我正在使用以下查询: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
然而,它仅匹配最后一行。