在Oracle中將設定條件的in語句改寫成exists語句
改寫前:
SELECT g.USER_CARDNO userCardno, p.PREMIUM
FROM POLICIES p
INNER JOIN gsuser g ON p.user_id = g.user_id
INNER JOIN gsuser gs ON gs.user_account = g.user_cardno
WHERE p.create_time >= to_date(#{treasure.startDate}, 'yyyy-mm-dd')
AND p.create_time <= sysdate
AND p.product_id IN (9,13,14,186,187,188,190,202,203)
AND p.policyflag = '4'
ORDER BY g.user_cardno,p.create_time ASC;
改寫後:
SELECT g.USER_CARDNO userCardno, p.PREMIUM
FROM POLICIES p
INNER JOIN gsuser g ON p.user_id = g.user_id
INNER JOIN gsuser gs ON gs.user_account = g.user_cardno
WHERE p.create_time >= to_date('2018-01-01', 'yyyy-mm-dd')
AND p.create_time <= sysdate
AND EXISTS(
select 1 from
(select 9 a from dual UNION all select 13 a from dual UNION all select 14 a from dual UNION all
select 186 a from dual UNION all select 187 a from dual UNION all select 188 a from dual UNION all
select 190 a from dual UNION all select 202 a from dual UNION all select 203 a from dual
)where p.product_id = a
)
AND p.policyflag = '4'
ORDER BY g.user_cardno,p.create_time ASC;
---------------------
作者:ybcljay
來源:CSDN
原文:https://blog.csdn.net/ybcljay/article/details/79579458
版權宣告:本文為博主原創文章,轉載請附上博文連結!