Performance 请帮助我优化下面提到的脚本,因为同一个表(即事件\审计\日志)已使用多次?
我不确定您想要实现什么,但我猜您想要使用新的最新更新提取行,并且状态_等于13和1035 在这种情况下,这应该是可行的:Performance 请帮助我优化下面提到的脚本,因为同一个表(即事件\审计\日志)已使用多次?,performance,sql-server-2008,query-tuning,Performance,Sql Server 2008,Query Tuning,我不确定您想要实现什么,但我猜您想要使用新的最新更新提取行,并且状态_等于13和1035 在这种情况下,这应该是可行的: select A.* from Incident_Audit_log a where incident_audit_log_id in (select top 1 incident_audit_log_id from Incident_Audit_log b where b.incident_id=a.incident_id and
select A.*
from Incident_Audit_log a where incident_audit_log_id in
(select top 1 incident_audit_log_id from Incident_Audit_log b
where b.incident_id=a.incident_id and b.status_did=a.status_did
and b.tracking_code_did = (select tracking_code_did
from Incident_Audit_log where update_date = (select MAX(update_date)
from Incident_Audit_log where Status_did in (103, 1035)
and incident_id = b.incident_id)
and incident_id = b.incident_id)
order by update_date asc)
如果没有,请提供更多信息。您想选择什么?这张桌子看起来怎么样?
select *
from (
select ROW_NUMBER() OVER(ORDER BY update_date DESC) AS rn,
*
from Incident_Audit_log
where status_did in (103, 1035)
) as SubQueryAlias
where rn = 1