通过将下面的 TeamRecords = 1 更改为 = 另一个数字,可以找到我更改为数量的行,只是有时它计数太多,这是奇怪的。创建新事件时,它有一个唯一编号,每次从任务表添加新分配时,它都会添加另一行 IncidentNumber,因此您可能有重复的事件编号行,我已使用下面的 seq = 1 删除了这些行. 创建新分配时,它会在任务表中创建一个新的 CreateddateTime,例如,您可以执行 Max(t.[CreatedDateTime] 来查找任何 IncidentNumber 的最后分配。因此,我需要找到 TeamRecords = 1该特定团队的所有记录,其中该团队只有一项任务。
这有帮助吗?这是我到目前为止...
Use TEST
Go
WITH RankResult AS
(
SELECT i.[IncidentNumber],
i.[CreatedDateTime],
i.[ResolutionDateAndTime],
i.[Priority],
i.[Status],
i.[ClientName],
i.[ClientSite],
t.[OwnerTeam],
t.[Owner],
row_number() over( partition by i.RecID
order by t.CreatedDateTime desc, t.OwnerTeam ) seq,
TeamRecords = COUNT(*) OVER(PARTITION BY t.ParentLink_RecID)
FROM Incident as i
Inner JOIN Task as t
ON i.RecID = t.ParentLink_RecID
WHERE t.OwnerTeam = 'Infrastructure Services'
AND i.CreatedDateTime >= '20121001'
AND i.CreatedDateTime <= '20131001'
)
SELECT DISTINCT
[IncidentNumber],
[CreatedDateTime],
[ResolutionDateAndTime],
[Priority],
[Status],
[ClientName],
[ClientSite],
[OwnerTeam],
[Owner]
FROM RankResult
Where TeamRecords = 1
And Seq = 1
Order By IncidentNumber Asc
GO