Skip to content

Commit

Permalink
Add min sequence number and creation date (#61)
Browse files Browse the repository at this point in the history
* Add min sequence number and creation date

* Remove trailing space
  • Loading branch information
sydneynotthecity authored Jul 9, 2024
1 parent 1772fad commit a4d2735
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions models/marts/ledger_current_state/accounts_current.sql
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,31 @@ with
{% endif %}
)

, account_date as (
select
account_id
, min(batch_run_date) as account_creation_date
, min(sequence_number) as min_sequence_number
from {{ ref('stg_accounts') }}
group by account_id
)

, get_creation_account as (
select
current_accts.*
, account_date.account_creation_date
, account_date.min_sequence_number
from current_accts
join account_date
on current_accts.account_id = account_date.account_id
where current_accts.row_nr = 1
)

/* Return the same fields as the `accounts` table */
select
account_id
, account_creation_date
, min_sequence_number
, balance
, buying_liabilities
, selling_liabilities
Expand All @@ -87,5 +109,4 @@ select
, batch_run_date
, batch_insert_ts as upstream_insert_ts
, current_timestamp() as batch_insert_ts
from current_accts
where row_nr = 1
from get_creation_account

0 comments on commit a4d2735

Please sign in to comment.