求sql高手优化sql语句

2025-03-24 06:35:50
推荐回答(2个)
回答1:

try this:

建议
1) getdate()方法用具体值替换,
2) cp 可以考虑
from (select * from com_position where posstate = 2) cp 替换,过滤条件cp.comoid in xxx也可以考虑加入这里,具体取决于
cp.comoid能过滤掉多少数据===〉目的,减少left join数据量
同样原理也可以考虑对cpp实行,方案就是
select top 20 ...
from (select xx from xxx where xxx) cp left join (select xxx from txxx where xx) cpp
on cp.posiid = cpp.posid

回答2:

初步查看,有一个条件与列是可以使用表关联进行合并替换的。
(select comname + '######' + convert(varchar(10), checkflag)
from com_info with(nolock)
where comid = cp.comid) as baseComInfo

and cp.comid in (select comid from com_info where checkflag = 2)