请帮助我优化下面提到的脚本为同一表(即.Incident_Audit_log)已被多次使用


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)

我不确定你想要实现什么,但我猜你想提取行与新的最新更新和status_did等于13和1035。

在这种情况下,这应该工作:

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

如果没有,请提供更多信息

相关内容

  • 没有找到相关文章

最新更新