0
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)
4

1 回答 1

0

我不确定您想要实现什么,但我想您想提取具有新的最新更新且 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

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

于 2015-10-17T09:23:43.870 回答