[英]joining same table multiple times in Oracle
嗨,我正在tuning
一個遺留代碼。 我們在一個大查詢中有以下 2 個表。
fnd_currencies, and pa_commitment_txns
我在 from 子句中看到了
fnd_currencies fca,
fnd_currencies fcr,
fnd_currencies fcp,
pa_commitment_txns pct
第一個表已被使用三次,並且已與同一個表的同一column
進行外部連接。
AND fca.currency_code(+) = pct.acct_currency_code
AND fcr.currency_code( +) = pct.receipt_currency_code
AND fcp.currency_code(+) = pct.project_currency_code
以上 3 行只能使用fnd_currencies
表處理一次。 有沒有更聰明的方法來做到這一點?
您可以使用子查詢因式分解子句確保只查詢一次fnd_currencies
。 這看起來像這樣(並通過使用 ANSI 92 語法讓@gordonlinoff 滿意):
with ccy as ( select *
from fnd_currencies )
select fca.descr as acct_currency
,fcr.descr as receipt_currency
,fcp.descr as project_currency
,pct.*
from pa_commitment_txns pct
left outer join ccy fca on fca.currency_code = pct.acct_currency_code
left outer join ccy fcr on fcr.currency_code = pct.receipt_currency_code
left outer join ccy fcp on fcp.currency_code = pct.project_currency_code
這是否會真正為您提供改進的執行時間取決於您尚未向我們保證的數據詳細信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.