首页 新闻 搜索 专区 学院

not in 效率低,怎么把not in 给替换掉

0
悬赏园豆:5 [已解决问题] 解决于 2016-10-11 08:11
SELECT sp.* FROM Prc_SalePolicy sp 
WHERE  
sp.UseState=1 
AND sp.AccId=3103 
AND  sp.Prc_SPId  NOT IN (SELECT Prc_SPId FROM Prc_CustSetSP  WHERE Fin_AccDtId=123425430000004)

not in 效率低,怎么把not in 给替换掉?

~冰的主页 ~冰 | 小虾三级 | 园豆:509
提问于:2016-10-10 17:38
< >
分享
最佳答案
0
SELECT sp.* FROM Prc_SalePolicy sp 
left join Prc_CustSetSP  pc on sp.Prc_SPId  =pc.Prc_SPId 
WHERE  
sp.UseState=1 
AND sp.AccId=3103 
AND Fin_AccDtId!=123425430000004)
SELECT sp.* FROM Prc_SalePolicy sp 
left join Prc_CustSetSP  pc on sp.Prc_SPId  =pc.Prc_SPId 
WHERE  
sp.UseState=1 
AND sp.AccId=3103 
AND Fin_AccDtId<123425430000004)
union
SELECT sp.* FROM Prc_SalePolicy sp 
left join Prc_CustSetSP  pc on sp.Prc_SPId  =pc.Prc_SPId 
WHERE  
sp.UseState=1 
AND sp.AccId=3103 
AND Fin_AccDtId>123425430000004)

 

收获园豆:5
吴瑞祥 | 高人七级 |园豆:29287 | 2016-10-10 18:03

试了,不行,自己想了一条,测试通过,还是感谢你的回答

SELECT sp.* FROM Prc_SalePolicy sp 
left join Prc_CustSetSP  pc on sp.Prc_SPId  =pc.Prc_SPId 
WHERE  
sp.UseState=1 
AND sp.AccId=3103 
AND Fin_AccDtId IS NULL

 

~冰 | 园豆:509 (小虾三级) | 2016-10-11 08:57
其他回答(1)
0

SELECT sp.* FROM Prc_SalePolicy sp
WHERE
sp.UseState=1
AND sp.AccId=3103
AND NOT EXISTS(SELECT 1 FROM Prc_CustSetSP pc WHERE pc.Prc_SPId = sp.Prc_SPId AND Fin_AccDtId=123425430000004)

ediclot | 园豆:202 (菜鸟二级) | 2016-12-30 16:54
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册