求sql高手优化sql语句
selecttop20cp.PosID,cp.PosName,cp.ComId,cp.ContactPerson,cp.WorkLocation,cp.PosDescri...
select
top 20 cp.PosID,
cp.PosName,
cp.ComId,
cp.ContactPerson,
cp.WorkLocation,
cp.PosDescription,
cp.ExamNotice,
cp.ExamAddress_P,
cp.ExamAddress_C,
cp.ExamAddress,
cp.Address_P,
cp.Address_C,
cp.Address,
cpp.CheckFlag,
cp.updatedate as UpdateTime ,
(
select
comname+'######'+convert(varchar(10),checkflag)
from com_info with(nolock)
where comid = cp.comid
)
as baseComInfo
from com_position cp with(nolock)
left join com_PosProperty cpp with(nolock) on cp.posid=cpp.posid
where cp.posstate = 2
and cp.endvaliddate>=getdate()
and (cpp.PosType=0 or cpp.postype is null)
and cp.comid in (select comid from com_info where checkflag = 2) 展开
top 20 cp.PosID,
cp.PosName,
cp.ComId,
cp.ContactPerson,
cp.WorkLocation,
cp.PosDescription,
cp.ExamNotice,
cp.ExamAddress_P,
cp.ExamAddress_C,
cp.ExamAddress,
cp.Address_P,
cp.Address_C,
cp.Address,
cpp.CheckFlag,
cp.updatedate as UpdateTime ,
(
select
comname+'######'+convert(varchar(10),checkflag)
from com_info with(nolock)
where comid = cp.comid
)
as baseComInfo
from com_position cp with(nolock)
left join com_PosProperty cpp with(nolock) on cp.posid=cpp.posid
where cp.posstate = 2
and cp.endvaliddate>=getdate()
and (cpp.PosType=0 or cpp.postype is null)
and cp.comid in (select comid from com_info where checkflag = 2) 展开
2个回答
展开全部
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
建议
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
展开全部
初步查看,有一个条件与列是可以使用表关联进行合并替换的。
(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)
(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)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询