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 给替换掉?
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)
试了,不行,自己想了一条,测试通过,还是感谢你的回答
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
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)