runtime
83 / 139

task Rolling windows & frames · hard

Debug: each account’s last posted amount

Find posted entries on accounts 1–30. Return transaction_id, account_id and last_amount: the account’s final posted amount (by posted_at, transaction_id). The query returns each row’s own amount. Fix it.

what to return

Columns
transaction_idaccount_idlast_amount in this order
Rows
1067 rows · any order
Skill
Repair the query’s logic and confirm the fix on changed data. Refresher: FIRST_VALUE, LAST_VALUE & frames →

expected result

expected result1067 rows · any order
transaction_idaccount_idlast_amount
431-6599
35971-6599
70991-6599

first 3 of 1067 rows

data you can query

transactions12 columns · 84,798 rows
transaction_idnumber · unique idaccount_idnumber · links to accountstransaction_typetextstatustextamount_centsnumberinitiated_atdate & timeposted_atdate & timedescriptiontextmerchant_idnumber · links to merchantsauthorization_idnumber · links to authorizationsrefund_idnumber · links to refundschargeback_idnumber · links to chargebacks
1103card_purchaseposted-13992025-01-01 04:00:002025-01-02 06:23:00TRUE STREAMING #7119591980NULLNULL
2377card_purchaseposted-39992025-01-01 04:00:002025-01-03 10:26:00VISTA GYM #1969656710NULLNULL
3442card_purchaseposted-6992025-01-01 04:00:002025-01-03 04:21:00WILLOW STREAMING #8179557848NULLNULL
4447card_purchaseposted-49992025-01-01 04:00:002025-01-02 12:31:00OAK GYM #9649697931NULLNULL
5450card_purchaseposted-24992025-01-01 04:00:002025-01-02 08:01:00BIRCH GYM #4989688096NULLNULL
6497card_purchaseposted-8992025-01-01 04:00:002025-01-02 12:11:00VERDE STREAMING #3859588870NULLNULL
7643card_purchaseposted-15492025-01-01 04:00:002025-01-03 07:31:00COBALT STREAMING #86495612146NULLNULL
8838card_purchaseposted-17992025-01-01 04:00:002025-01-02 07:33:00COBALT STREAMING #86495615853NULLNULL
91328card_purchaseposted-39992025-01-01 04:00:002025-01-03 11:00:00VECTOR GYM #94596425656NULLNULL
101631card_purchaseposted-29992025-01-01 04:00:002025-01-03 06:14:00VISTA GYM #19696531252NULLNULL
transaction_idnumber · unique id
1
account_idnumber · links to accounts
103
transaction_typetext
card_purchase
statustext
posted
amount_centsnumber
-1399
initiated_atdate & time
2025-01-01 04:00:00
posted_atdate & time
2025-01-02 06:23:00
descriptiontext
TRUE STREAMING #711
merchant_idnumber · links to merchants
959
authorization_idnumber · links to authorizations
1980
refund_idnumber · links to refunds
NULL
chargeback_idnumber · links to chargebacks
NULL
transaction_idnumber · unique id
2
account_idnumber · links to accounts
377
transaction_typetext
card_purchase
statustext
posted
amount_centsnumber
-3999
initiated_atdate & time
2025-01-01 04:00:00
posted_atdate & time
2025-01-03 10:26:00
descriptiontext
VISTA GYM #196
merchant_idnumber · links to merchants
965
authorization_idnumber · links to authorizations
6710
refund_idnumber · links to refunds
NULL
chargeback_idnumber · links to chargebacks
NULL
transaction_idnumber · unique id
3
account_idnumber · links to accounts
442
transaction_typetext
card_purchase
statustext
posted
amount_centsnumber
-699
initiated_atdate & time
2025-01-01 04:00:00
posted_atdate & time
2025-01-03 04:21:00
descriptiontext
WILLOW STREAMING #817
merchant_idnumber · links to merchants
955
authorization_idnumber · links to authorizations
7848
refund_idnumber · links to refunds
NULL
chargeback_idnumber · links to chargebacks
NULL
transaction_idnumber · unique id
4
account_idnumber · links to accounts
447
transaction_typetext
card_purchase
statustext
posted
amount_centsnumber
-4999
initiated_atdate & time
2025-01-01 04:00:00
posted_atdate & time
2025-01-02 12:31:00
descriptiontext
OAK GYM #964
merchant_idnumber · links to merchants
969
authorization_idnumber · links to authorizations
7931
refund_idnumber · links to refunds
NULL
chargeback_idnumber · links to chargebacks
NULL
transaction_idnumber · unique id
5
account_idnumber · links to accounts
450
transaction_typetext
card_purchase
statustext
posted
amount_centsnumber
-2499
initiated_atdate & time
2025-01-01 04:00:00
posted_atdate & time
2025-01-02 08:01:00
descriptiontext
BIRCH GYM #498
merchant_idnumber · links to merchants
968
authorization_idnumber · links to authorizations
8096
refund_idnumber · links to refunds
NULL
chargeback_idnumber · links to chargebacks
NULL
transaction_idnumber · unique id
6
account_idnumber · links to accounts
497
transaction_typetext
card_purchase
statustext
posted
amount_centsnumber
-899
initiated_atdate & time
2025-01-01 04:00:00
posted_atdate & time
2025-01-02 12:11:00
descriptiontext
VERDE STREAMING #385
merchant_idnumber · links to merchants
958
authorization_idnumber · links to authorizations
8870
refund_idnumber · links to refunds
NULL
chargeback_idnumber · links to chargebacks
NULL
transaction_idnumber · unique id
7
account_idnumber · links to accounts
643
transaction_typetext
card_purchase
statustext
posted
amount_centsnumber
-1549
initiated_atdate & time
2025-01-01 04:00:00
posted_atdate & time
2025-01-03 07:31:00
descriptiontext
COBALT STREAMING #864
merchant_idnumber · links to merchants
956
authorization_idnumber · links to authorizations
12146
refund_idnumber · links to refunds
NULL
chargeback_idnumber · links to chargebacks
NULL
transaction_idnumber · unique id
8
account_idnumber · links to accounts
838
transaction_typetext
card_purchase
statustext
posted
amount_centsnumber
-1799
initiated_atdate & time
2025-01-01 04:00:00
posted_atdate & time
2025-01-02 07:33:00
descriptiontext
COBALT STREAMING #864
merchant_idnumber · links to merchants
956
authorization_idnumber · links to authorizations
15853
refund_idnumber · links to refunds
NULL
chargeback_idnumber · links to chargebacks
NULL
transaction_idnumber · unique id
9
account_idnumber · links to accounts
1328
transaction_typetext
card_purchase
statustext
posted
amount_centsnumber
-3999
initiated_atdate & time
2025-01-01 04:00:00
posted_atdate & time
2025-01-03 11:00:00
descriptiontext
VECTOR GYM #945
merchant_idnumber · links to merchants
964
authorization_idnumber · links to authorizations
25656
refund_idnumber · links to refunds
NULL
chargeback_idnumber · links to chargebacks
NULL
transaction_idnumber · unique id
10
account_idnumber · links to accounts
1631
transaction_typetext
card_purchase
statustext
posted
amount_centsnumber
-2999
initiated_atdate & time
2025-01-01 04:00:00
posted_atdate & time
2025-01-03 06:14:00
descriptiontext
VISTA GYM #196
merchant_idnumber · links to merchants
965
authorization_idnumber · links to authorizations
31252
refund_idnumber · links to refunds
NULL
chargeback_idnumber · links to chargebacks
NULL

first 10 of 84,798 rows · your queries use all of them

solution.sql
 
Output

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

Debug: each account’s last posted amount — SQL practice · Runtime