runtime
134 / 139

task Deduplication · hard

Retried authorization requests

Find merchants with at least one retried request. Return merchant_id, attempts (rows), requests (distinct request_key), and approved_amount: the sum of amount over requests whose final attempt (latest requested_at, then highest authorization_id) was approved, rounded to 2 decimals.

what to return

Columns
merchant_idattemptsrequestsapproved_amount in this order
Rows
208 rows · any order
Skill
Count requests, not retries. Refresher: Latest row per group →

expected result

expected result208 rows · any order
merchant_idattemptsrequestsapproved_amount
130291543.58
1032311427.96
1629281288.58

first 3 of 208 rows

data you can query

authorizations10 columns · 40,508 rows
authorization_idnumber · unique idrequest_keytextcard_idnumber · links to cardsmerchant_idnumber · links to merchantsrequested_atdate & timeamountdecimalcurrencytextchanneltextstatustextdecline_reasontext
1req_000000114652025-01-06 18:49:43100USDin_storedeclinedinsufficient_funds
2req_000000214202025-01-08 20:45:556.9USDin_storedeclinedinsufficient_funds
3req_00000031322025-01-21 15:28:5376.55USDin_storeapprovedNULL
4req_000000415162025-01-27 11:09:51175USDin_storeapprovedNULL
5req_000000511592025-01-29 15:06:2157.71USDin_storeapprovedNULL
6req_000000612012025-02-09 23:15:3437.17USDonlineapprovedNULL
7req_000000717132025-02-10 17:37:5344.01USDin_storeapprovedNULL
8req_00000081162025-02-16 22:58:1892.88USDin_storeapprovedNULL
9req_000000912242025-02-28 16:40:4157.76USDin_storeapprovedNULL
10req_000001017782025-03-27 21:01:2991.31USDonlineapprovedNULL
authorization_idnumber · unique id
1
request_keytext
req_0000001
card_idnumber · links to cards
1
merchant_idnumber · links to merchants
465
requested_atdate & time
2025-01-06 18:49:43
amountdecimal
100
currencytext
USD
channeltext
in_store
statustext
declined
decline_reasontext
insufficient_funds
authorization_idnumber · unique id
2
request_keytext
req_0000002
card_idnumber · links to cards
1
merchant_idnumber · links to merchants
420
requested_atdate & time
2025-01-08 20:45:55
amountdecimal
6.9
currencytext
USD
channeltext
in_store
statustext
declined
decline_reasontext
insufficient_funds
authorization_idnumber · unique id
3
request_keytext
req_0000003
card_idnumber · links to cards
1
merchant_idnumber · links to merchants
32
requested_atdate & time
2025-01-21 15:28:53
amountdecimal
76.55
currencytext
USD
channeltext
in_store
statustext
approved
decline_reasontext
NULL
authorization_idnumber · unique id
4
request_keytext
req_0000004
card_idnumber · links to cards
1
merchant_idnumber · links to merchants
516
requested_atdate & time
2025-01-27 11:09:51
amountdecimal
175
currencytext
USD
channeltext
in_store
statustext
approved
decline_reasontext
NULL
authorization_idnumber · unique id
5
request_keytext
req_0000005
card_idnumber · links to cards
1
merchant_idnumber · links to merchants
159
requested_atdate & time
2025-01-29 15:06:21
amountdecimal
57.71
currencytext
USD
channeltext
in_store
statustext
approved
decline_reasontext
NULL
authorization_idnumber · unique id
6
request_keytext
req_0000006
card_idnumber · links to cards
1
merchant_idnumber · links to merchants
201
requested_atdate & time
2025-02-09 23:15:34
amountdecimal
37.17
currencytext
USD
channeltext
online
statustext
approved
decline_reasontext
NULL
authorization_idnumber · unique id
7
request_keytext
req_0000007
card_idnumber · links to cards
1
merchant_idnumber · links to merchants
713
requested_atdate & time
2025-02-10 17:37:53
amountdecimal
44.01
currencytext
USD
channeltext
in_store
statustext
approved
decline_reasontext
NULL
authorization_idnumber · unique id
8
request_keytext
req_0000008
card_idnumber · links to cards
1
merchant_idnumber · links to merchants
16
requested_atdate & time
2025-02-16 22:58:18
amountdecimal
92.88
currencytext
USD
channeltext
in_store
statustext
approved
decline_reasontext
NULL
authorization_idnumber · unique id
9
request_keytext
req_0000009
card_idnumber · links to cards
1
merchant_idnumber · links to merchants
224
requested_atdate & time
2025-02-28 16:40:41
amountdecimal
57.76
currencytext
USD
channeltext
in_store
statustext
approved
decline_reasontext
NULL
authorization_idnumber · unique id
10
request_keytext
req_0000010
card_idnumber · links to cards
1
merchant_idnumber · links to merchants
778
requested_atdate & time
2025-03-27 21:01:29
amountdecimal
91.31
currencytext
USD
channeltext
online
statustext
approved
decline_reasontext
NULL

first 10 of 40,508 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.

Retried authorization requests — SQL practice · Runtime