subquery to CTE
This commit is contained in:
parent
487f6701e3
commit
883618add1
1 changed files with 16 additions and 15 deletions
|
|
@ -1,5 +1,20 @@
|
|||
with
|
||||
raw_bank_transactions as (select * from {{ source("xero", "bank_transactions") }}),
|
||||
transaction_signs as (
|
||||
-- making this tiny CTE to be able to reference the transaction_sign col
|
||||
-- in the main body easily and avoid plastering the case-when a
|
||||
-- gazillion times.
|
||||
select
|
||||
{{ adapter.quote("BankTransactionID") }} as id_bank_transaction,
|
||||
case
|
||||
when {{ adapter.quote("Type") }} like '%SPEND%'
|
||||
then -1
|
||||
when {{ adapter.quote("Type") }} like '%RECEIVE%'
|
||||
then 1
|
||||
else null
|
||||
end as transaction_sign
|
||||
from raw_bank_transactions
|
||||
),
|
||||
stg_xero__bank_transactions as (
|
||||
select
|
||||
{{ adapter.quote("BankTransactionID") }} as id_bank_transaction,
|
||||
|
|
@ -39,21 +54,7 @@ with
|
|||
{{ adapter.quote("_airbyte_extracted_at") }} as dwh_extracted_at_utc
|
||||
from raw_bank_transactions bt
|
||||
left join
|
||||
(
|
||||
-- making this tiny subquery to be able to reference the
|
||||
-- transaction_sign col above easily and avoid plastering the
|
||||
-- case-when a gazillion times.
|
||||
select
|
||||
{{ adapter.quote("BankTransactionID") }} as id_bank_transaction,
|
||||
case
|
||||
when {{ adapter.quote("Type") }} like '%SPEND%'
|
||||
then -1
|
||||
when {{ adapter.quote("Type") }} like '%RECEIVE%'
|
||||
then 1
|
||||
else null
|
||||
end as transaction_sign
|
||||
from raw_bank_transactions
|
||||
) ts
|
||||
transaction_signs ts
|
||||
on bt.{{ adapter.quote("BankTransactionID") }} = ts.id_bank_transaction
|
||||
)
|
||||
select *
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue