程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> 關於Oracle數據庫 >> oracle join on 數據過濾問題

oracle join on 數據過濾問題

編輯:關於Oracle數據庫
代碼如下:

select a.f_username
from
(
SELECT /*+parallel(gu,4)*/distinct gu.f_username
FROM t_base_succprouser gu
where gu.f_expectenddate > (select trunc(sysdate,'Y')FROM DUAL)
and gu.f_lotid=1
and gu.f_playid=4
and gu.f_paymoney>=1500
) A
left join
(
select
from t_base_vip_customes
and ((vu.f_passeddate is null ) or (vu.f_passeddate > trunc(sysdate,'Y') ))
and ((vu.f_lotid is null ) or (vu.f_lotid=1))
and ((vu.f_playid is null ) or (vu.f_playid=4))
and ((vu.f_condtionid is null ) or (vu.f_condtionid=3))
)B
on A.f_username=B.f_usernam
where b.f_username is null

采用下面的語句 只能查出部分用戶
代碼如下:

SELECT /*+parallel(gu,4)*/distinct gu.f_username
FROM t_base_succprouser gu
left join t_base_vip_customes VU on gu.f_username=vu.f_username
gu.f_expectenddate > (select trunc(sysdate,'Y')FROM DUAL)
and gu.f_lotid=rec_viplotplay.f_lotid
and gu.f_playid=rec_viplotPlay.f_Playid
and gu.f_paymoney>=rec_viplotPlay.F_Conditon_ValuesA
and ((vu.f_passeddate is null ) or (vu.f_passeddate > trunc(sysdate,'Y') ))
and ((vu.f_lotid is null ) or (vu.f_lotid=rec_viplotplay.f_lotid))
and ((vu.f_playid is null ) or (vu.f_playid=rec_viplotPlay.f_Playid))
and ((vu.f_condtionid is null ) or (vu.f_condtionid=rec_viplotPlay.F_CondtionID))
and vu.f_username is null

執行計劃:
代碼如下:

SELECT STATEMENT, GOAL = ALL_ROWS
HASH UNIQUE
NESTED LOOPS OUTER
PARTITION RANGE ALL
TABLE ACCESS FULL Object name=T_BASE_SUCCPROUSER
VIEW
FILTER
TABLE ACCESS FULL Object name=T_BASE_VIP_CUSTOMES
FAST DUAL

後來改成了下面就能全部查出來了
代碼如下:

SELECT /*+parallel(gu,4)*/distinct gu.f_username
FROM t_base_succprouser gu
left join t_base_vip_customes VU on gu.f_username=vu.f_username
and ((vu.f_passeddate is null ) or (vu.f_passeddate > trunc(sysdate,'Y') ))
and ((vu.f_lotid is null ) or (vu.f_lotid=rec_viplotplay.f_lotid))
and ((vu.f_playid is null ) or (vu.f_playid=rec_viplotPlay.f_Playid))
and ((vu.f_condtionid is null ) or (vu.f_condtionid=rec_viplotPlay.F_CondtionID))

where gu.f_expectenddate > (select trunc(sysdate,'Y')FROM DUAL)
and gu.f_lotid=rec_viplotplay.f_lotid
and gu.f_playid=rec_viplotPlay.f_Playid
and gu.f_paymoney>=rec_viplotPlay.F_Conditon_ValuesA
and vu.f_username is null
執行計劃:
SELECT STATEMENT, GOAL = ALL_ROWS
HASH UNIQUE
FILTER
NESTED LOOPS OUTER
TABLE ACCESS BY GLOBAL INDEX ROWID Object name=T_BASE_SUCCPROUSER
INDEX RANGE SCAN Object name=IX_BASE_PROUSER_LOWEX
FAST DUAL
VIEW
TABLE ACCESS FULL Object name=T_BASE_VIP_CUSTOMES

oracle 不懂先把數據給過濾掉然後在來連接嗎? 太笨了!而且這樣把符合條件的數據也過濾掉了
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved