2015-10-16 60 views
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) 
+0

你想要選擇什麼?桌子是怎樣的? – dcieslak

回答

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 

如果不是,請提供更多信息。

相關問題