Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance 请帮助我优化下面提到的脚本,因为同一个表(即事件\审计\日志)已使用多次?_Performance_Sql Server 2008_Query Tuning - Fatal编程技术网

Performance 请帮助我优化下面提到的脚本,因为同一个表(即事件\审计\日志)已使用多次?

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

我不确定您想要实现什么,但我猜您想要使用新的最新更新提取行,并且状态_等于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  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