oracle 在SQL中使用不同表中的列进行查询

zu0ti5jz  于 2023-05-16  发布在  Oracle
关注(0)|答案(1)|浏览(189)

以下是初始SQL查询:

SELECT  a.displaynamewithhierarchy as account_name,
        BUILTIN.DF(a.accttype) as account_type,
        t.id as internal_id,
        BUILTIN.DF(t.type) as transaction_type,
        t.trandate as transaction_date,
        BUILTIN.DF(t.postingperiod) as period,
        BUILTIN.CONSOLIDATE(tl.amount, 'INCOME', 'DEFAULT', 'DEFAULT', 1, t.postingperiod, 1) as amount,
        BUILTIN.DF(t.currency) as currency,
        tl.debitforeignamount as amount_debit_foreign,
        tl.creditforeignamount as amount_credit_foreign
FROM transaction t
LEFT JOIN transactionline tl on t.id = tl.transaction
LEFT JOIN transactionaccountingline tal on tl.id = tal.transactionline and t.id = tal.transaction
LEFT JOIN account a on tal.account = a.id
WHERE t.tranid = 'JE2012020'

我想改变t.postingperiod(从BUILTIN.CONSOLIDATE()函数),并使用t.trandate的发布周期ID(该字段将是postingperiod表中的id)。
postingperiod表如下所示:Posting Period Table
你知道如何修改查询吗?

s5a0g9ez

s5a0g9ez1#

看起来你只需要加入这个表,并在你想要的地方使用SELECT列表中的列。根据你的表结构,可能像这样连接:

INNER JOIN postingperiod pp 
  ON t.trandate BETWEEN pp.startdate AND pp.enddate + INTERVAL '1' DAY - INTERVAL '1' SECOND 
  AND pp.isquarter='F'

相关问题