[英]joining same table multiple times in Oracle
Hi I am tuning
one legacy code.嗨,我正在
tuning
一个遗留代码。 we have below 2 tables in a big query.我们在一个大查询中有以下 2 个表。
fnd_currencies, and pa_commitment_txns
I have seen in from clause我在 from 子句中看到了
fnd_currencies fca,
fnd_currencies fcr,
fnd_currencies fcp,
pa_commitment_txns pct
first table has been used thrice and it has been outer joined with same column
with same table.第一个表已被使用三次,并且已与同一个表的同一
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
Can above 3 lines be handled using fnd_currencies
table only once.以上 3 行只能使用
fnd_currencies
表处理一次。 is there any smarter way to do that?有没有更聪明的方法来做到这一点?
You can ensure that you only query fnd_currencies
once by using a subquery factoring clause.您可以使用子查询因式分解子句确保只查询一次
fnd_currencies
。 That would look like this (and keeps @gordonlinoff happy by using ANSI 92 syntax):这看起来像这样(并通过使用 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
Whether this will actually give you an improved execution time depends on the details of your data, which you haven't vouchsafed to us.这是否会真正为您提供改进的执行时间取决于您尚未向我们保证的数据详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.