runtime
123 / 139

task Correlated subqueries · medium

Purchases far above a card’s norm

Return authorization_id, card_id, amount and card_avg (the card’s average approved amount, 2 decimals) for approved authorizations more than three times their card’s average approved amount.

what to return

Columns
authorization_idcard_idamountcard_avg in this order
Rows
2226 rows · any order
Skill
Flag outliers relative to each entity’s own baseline. Refresher: Subqueries →

expected result

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

expected result2226 rows · any order
authorization_idcard_idamountcard_avg
493201.3466.07
38417544.37
665342.8358.78

first 3 of 2226 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.

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
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

first 6 of 40,508 rows · your queries use all of them

solution.sql
 

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

Purchases far above a card’s norm — SQL practice · Runtime