下面的语句执行速度很快:
select psd_nid,count(*) as vip_qh from psvip where exists(
select * from pscj a left join pszx b on
a.psvip_nid=b.psvip_nid and a.c7=b.z6 and isnull(a.sxmx_nid,0)=isnull(b.sxmx_nid,0)
where a.psvip_nid=psvip.nid and (b.nid is null Or isnull(a.c8,0) > isnull(b.z7,0))
)
group by psd_nid
但 只要加上条件:and psd_nid = 2 ,速度就变得很慢,如何让它速度一样呢???
select psd_nid,count(*) as vip_qh from psvip where exists(
select * from pscj a left join pszx b on
a.psvip_nid=b.psvip_nid and a.c7=b.z6 and isnull(a.sxmx_nid,0)=isnull(b.sxmx_nid,0)
where a.psvip_nid=psvip.nid and (b.nid is null Or isnull(a.c8,0) > isnull(b.z7,0))
)
and psd_nid = 2
group by psd_nid
我该如何做 才能让它查询变快呢?
------解决方案--------------------
ctrl+m 然后执行你那两个语句,然后贴图
------解决方案--------------------
上执行计划!
------解决方案--------------------
select psd_nid,count(*) as vip_qh from psvip where exists(
select top 1 pscj.psvip_nid from pscj a left join pszx b on
a.psvip_nid=b.psvip_nid and a.c7=b.z6 and isnull(a.sxmx_nid,0)=isnull(b.sxmx_nid,0)
where a.psvip_nid=psvip.nid and (b.nid is null Or isnull(a.c8,0) > isnull(b.z7,0))
)
and psd_nid = 2
group by psd_nid
改成这样试试
------解决方案--------------------
分别执行:
sp_help 'pscj'
sp_help 'vip_qh'
贴结果