在我的项目中,我需要在同一个表中找到基于旧版本和新版本的差异任务。左外连接Sql server中的性能问题
id | task | latest_Rev
1 A N
1 B N
2 C Y
2 A Y
2 B Y
预期结果:
id | task | latest_Rev
2 C Y
所以,我想下面的查询
Select new.*
from Rev_tmp nw with (nolock)
left outer
join rev_tmp old with (nolock)
on nw.id -1 = old.id
and nw.task = old.task
and nw.latest_rev = 'y'
where old.task is null
,当我的表具有20K以上的记录此查询需要更多的时间? 如何缩短时间?
在我的公司不允许使用子查询
比什么呢?你的表格如何索引?什么是查询计划? –
不允许使用子查询听起来很奇怪。你允许使用CTE吗?派生表?你为什么被允许使用NOLOCK? –
我的表没有所有主要字段的聚集索引。它是一个规则。 @JamesZ。 – Sathish