我正在使用 SQL 2000。我已经到了可以根据一组复杂的条件删除所有不需要的重复项的地步,但是现在查询需要几个小时才能完成,而过去只需要大约 3.5 分钟才能获得包含重复项的数据。
为了清晰:我可以有一个重复的 rpt.Name 字段,只要 rpt.HostName 或 rpt.SystemSerialNumber 字段也不同。此外,我必须根据四个不同列的时间戳来确定要保留的条目,因为其中一些列缺少时间戳。
任何帮助是极大的赞赏!
SELECT
rpt.[Name],
rpt.LastAgentExecution,
rpt.GroupName,
rpt.PackageName,
rpt.PackageVersion,
rpt.ProcedureName,
rpt.HostName,
rpt.SystemSerialNumber,
rpt.JobCreationTime,
rpt.JobActivationTime,
rpt.[Job Completion Time]
FROM DSM_StandardGroupMembersProcedureActivityViewExt rpt
WHERE
(
(
rpt.GroupName = 'Adobe Acrobat 7 Deploy'
OR rpt.GroupName = 'Adobe Acrobat 8 Deploy'
)
AND
(
(rpt.PackageName = 'Adobe Acrobat 7' AND rpt.PackageVersion = '-1.0')
OR (rpt.PackageName = 'Adobe Acrobat 8' AND rpt.PackageVersion = '-3.0')
)
)
AND NOT EXISTS
(
SELECT *
FROM DSM_StandardGroupMembersProcedureActivityViewExt rpt_dupe
WHERE
(
(
rpt.GroupName = 'Adobe Acrobat 7 Deploy'
OR rpt.GroupName = 'Adobe Acrobat 8 Deploy'
)
AND
(
(rpt.PackageName = 'Adobe Acrobat 7' AND rpt.PackageVersion = '-1.0')
OR (rpt.PackageName = 'Adobe Acrobat 8' AND rpt.PackageVersion = '-3.0')
)
AND
(
(rpt_dupe.[Name] = rpt.[Name])
AND
(
(rpt_dupe.SystemSerialNumber = rpt.SystemSerialNumber)
OR (rpt_dupe.HostName = rpt.HostName)
)
AND
(
(rpt_dupe.LastAgentExecution < rpt.LastAgentExecution)
OR (rpt_dupe.JobActivationTime < rpt.JobActivationTime)
OR (rpt_dupe.JobCreationTime < rpt.JobCreationTime)
OR (rpt_dupe.[Job Completion Time] < rpt.[Job Completion Time])
)
)
)
)