当前位置:Gxlcms > 数据库问题 > Sql server not in优化

Sql server not in优化

时间:2021-07-01 10:21:17 帮助过:21人阅读

oracle在执行IN子查询过程中,先执行子查询结果放入临时表再进行主查询;   而exists先运行主查询,再执行子查询查到第一个匹配项 如:查询 A表中没有和B表或C表相连的数据    select A.id,A.reads,A.addtime  from A  where A.person_id not in (select user_id from B )  or A.worksite_id not in (select id from C)  order by A.addtime desc 程序执行时间:40109.38毫秒    select A.id,A.reads,A.addtime from A  where not exists (select id FROM B where B.user_id=A.person_id)  or not exists (select id FROM C where C.id=A.worksite_id)  order by Sendorder.addtime desc 程序执行时间:8531.25毫秒 

 

ms ssql 实例:

select 
subscriber_id
from 
NewsLetterSystem_CampaignCategorySubscriber ccs WITH ( NOLOCK )
where NOT EXISTS(
SELECT  distinct subscriber_id
FROM    NewsLetterSystem_OpenTracking ot WITH ( NOLOCK ) 
WHERE  ot.subscriber_id=ccs.subscriber_id and ot.campaign_id = 52801)
and ccs.campaign_id = 52801 and ccs.status_id = 1

 

Sql server not in优化

标签:campaign   open   code   blog   rom   let   div   category   from   

人气教程排行