ctes for first isntead of last xe rate
This commit is contained in:
parent
7707bc1254
commit
a07a50793b
1 changed files with 16 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ with
|
|||
stg_xedotcom__exchange_rates as (
|
||||
select * from {{ ref("stg_xedotcom__exchange_rates") }}
|
||||
),
|
||||
-- CTEs for projecting forwards
|
||||
most_recent_xe_date_per_curr_pair as (
|
||||
select from_currency, to_currency, max(rate_date_utc) as most_recent_date_utc
|
||||
from stg_xedotcom__exchange_rates
|
||||
|
|
@ -51,7 +52,22 @@ with
|
|||
now() as updated_at_utc
|
||||
from future_dates future_dates
|
||||
cross join last_xe_rate_per_curr_pair last_rate
|
||||
),
|
||||
oldest_xe_date_per_curr_pair as (
|
||||
select from_currency, to_currency, max(rate_date_utc) as oldest_date_utc
|
||||
from stg_xedotcom__exchange_rates
|
||||
group by 1, 2
|
||||
),
|
||||
first_xe_rate_per_curr_pair as (
|
||||
select xe.from_currency, xe.to_currency, xe.rate
|
||||
from stg_xedotcom__exchange_rates xe
|
||||
inner join
|
||||
oldest_xe_date_per_curr_pair recent
|
||||
on xe.from_currency = recent.from_currency
|
||||
and xe.to_currency = recent.to_currency
|
||||
and xe.rate_date_utc = recent.oldest_date_utc
|
||||
)
|
||||
-- here we union actual stuff, future projected stuff and past assumed stuff
|
||||
select
|
||||
concat(
|
||||
xe.from_currency, xe.to_currency, xe.rate_date_utc, 'xedotcom', 'actual'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue