runtime
58 / 139

task INSERT / UPDATE / DELETE · hard

A replay-safe ledger load

partner_feed contains payroll references, some delivered twice. Load it into partner_ledger (external_ref is the primary key) so that running the same load again adds nothing. Return accounts (distinct account_id), entries and total_cents from partner_ledger.

what to return

Columns
accountsentriestotal_cents in this order
Rows
1 row · any order
Skill
Load a feed so replays change nothing. Refresher: Idempotent incremental UPSERT & stale updates →

expected result

Your query should return exactly these columns and values. Run it and compare.

expected result1 row · any order
accountsentriestotal_cents
2823998569567

all 1 rows

data you can query

Finance / Payments dataset: the first 6 rows of each table. Under each column name: the kind of value it holds, and which table it links to. Your queries run on all rows.

partner_feed4 columns · 271 rows
external_reftextaccount_idnumberamount_centsnumberposted_atdate & time
EXT-150324794242025-01-03 09:00:00
EXT-1504312405132025-01-03 09:00:00
EXT-15053811950962025-01-03 09:00:00
EXT-1506472310792025-01-03 09:00:00
EXT-1507591525772025-01-03 09:00:00
EXT-359711509992025-01-10 09:00:00
external_reftext
EXT-1503
account_idnumber
24
amount_centsnumber
79424
posted_atdate & time
2025-01-03 09:00:00
external_reftext
EXT-1504
account_idnumber
31
amount_centsnumber
240513
posted_atdate & time
2025-01-03 09:00:00
external_reftext
EXT-1505
account_idnumber
38
amount_centsnumber
1195096
posted_atdate & time
2025-01-03 09:00:00
external_reftext
EXT-1506
account_idnumber
47
amount_centsnumber
231079
posted_atdate & time
2025-01-03 09:00:00
external_reftext
EXT-1507
account_idnumber
59
amount_centsnumber
152577
posted_atdate & time
2025-01-03 09:00:00
external_reftext
EXT-3597
account_idnumber
1
amount_centsnumber
150999
posted_atdate & time
2025-01-10 09:00:00

first 6 of 271 rows · your queries use all of them

partner_ledger4 columns · 0 rows
external_reftext · unique idaccount_idnumber · links to accountsamount_centsnumberposted_attext

all 0 rows

solution.sql
 

Hints and the answer are always available. Using them counts the question as solved with help.

A replay-safe ledger load — SQL practice · Runtime