runtime
25 / 139

task Correlated subqueries · medium

Big spenders for their state

Using settled card amounts, return customer_id, state and settled_cents for customers whose total settled card spend is above the average total of customers in the same state (only customers with any settled spend count toward that average).

what to return

Columns
customer_idstatesettled_cents in this order
Rows
355 rows · any order
Skill
Compare each row with an average of its own group. Refresher: Subqueries →

expected result

expected result355 rows · any order
customer_idstatesettled_cents
3AZ131000
4IL715055
11NC184149

first 3 of 355 rows

data you can query

customers7 columns · 1,120 rows
customer_idnumber · unique idfull_nametextcitytextstatetextdate_of_birthdatecustomer_sincedaterisk_tiertext
1Tara KowalskiNewarkNJ1957-10-312022-02-24low
2Anna OkaforDetroitMI1985-03-012025-06-11medium
3Jasmine ChangPhoenixAZ2005-12-142024-07-07medium
4Victor YamamotoChicagoIL1996-06-222023-07-18low
5Ryan FernandezMinneapolisMN1965-07-232018-02-14low
6Leah RussellSeattleWA1965-01-022024-08-16low
7Nina AndersonAtlantaGA1987-01-062024-08-20low
8Luis OrtizSeattleWA1962-09-222023-08-20high
9Ava MitchellPhoenixAZ1976-02-082025-06-11low
10Deepa MillerJacksonvilleFL1996-02-162025-06-11high
customer_idnumber · unique id
1
full_nametext
Tara Kowalski
citytext
Newark
statetext
NJ
date_of_birthdate
1957-10-31
customer_sincedate
2022-02-24
risk_tiertext
low
customer_idnumber · unique id
2
full_nametext
Anna Okafor
citytext
Detroit
statetext
MI
date_of_birthdate
1985-03-01
customer_sincedate
2025-06-11
risk_tiertext
medium
customer_idnumber · unique id
3
full_nametext
Jasmine Chang
citytext
Phoenix
statetext
AZ
date_of_birthdate
2005-12-14
customer_sincedate
2024-07-07
risk_tiertext
medium
customer_idnumber · unique id
4
full_nametext
Victor Yamamoto
citytext
Chicago
statetext
IL
date_of_birthdate
1996-06-22
customer_sincedate
2023-07-18
risk_tiertext
low
customer_idnumber · unique id
5
full_nametext
Ryan Fernandez
citytext
Minneapolis
statetext
MN
date_of_birthdate
1965-07-23
customer_sincedate
2018-02-14
risk_tiertext
low
customer_idnumber · unique id
6
full_nametext
Leah Russell
citytext
Seattle
statetext
WA
date_of_birthdate
1965-01-02
customer_sincedate
2024-08-16
risk_tiertext
low
customer_idnumber · unique id
7
full_nametext
Nina Anderson
citytext
Atlanta
statetext
GA
date_of_birthdate
1987-01-06
customer_sincedate
2024-08-20
risk_tiertext
low
customer_idnumber · unique id
8
full_nametext
Luis Ortiz
citytext
Seattle
statetext
WA
date_of_birthdate
1962-09-22
customer_sincedate
2023-08-20
risk_tiertext
high
customer_idnumber · unique id
9
full_nametext
Ava Mitchell
citytext
Phoenix
statetext
AZ
date_of_birthdate
1976-02-08
customer_sincedate
2025-06-11
risk_tiertext
low
customer_idnumber · unique id
10
full_nametext
Deepa Miller
citytext
Jacksonville
statetext
FL
date_of_birthdate
1996-02-16
customer_sincedate
2025-06-11
risk_tiertext
high

first 10 of 1,120 rows · your queries use all of them

accounts7 columns · 2,109 rows
account_idnumber · unique idcustomer_idnumber · links to customersaccount_typetextopened_atdateclosed_attextcredit_limit_centsnumberopening_balance_centsnumber
11checking2022-02-24NULLNULL43125
22checking2025-06-11NULLNULL0
33checking2024-07-07NULLNULL216925
43savings2024-10-07NULLNULL475941
53credit_card2024-09-26NULL1020600-339148
64checking2023-07-18NULLNULL155995
74savings2024-04-20NULLNULL1484759
85checking2018-02-14NULLNULL57994
96checking2024-08-16NULLNULL72360
107checking2024-08-20NULLNULL83275
account_idnumber · unique id
1
customer_idnumber · links to customers
1
account_typetext
checking
opened_atdate
2022-02-24
closed_attext
NULL
credit_limit_centsnumber
NULL
opening_balance_centsnumber
43125
account_idnumber · unique id
2
customer_idnumber · links to customers
2
account_typetext
checking
opened_atdate
2025-06-11
closed_attext
NULL
credit_limit_centsnumber
NULL
opening_balance_centsnumber
0
account_idnumber · unique id
3
customer_idnumber · links to customers
3
account_typetext
checking
opened_atdate
2024-07-07
closed_attext
NULL
credit_limit_centsnumber
NULL
opening_balance_centsnumber
216925
account_idnumber · unique id
4
customer_idnumber · links to customers
3
account_typetext
savings
opened_atdate
2024-10-07
closed_attext
NULL
credit_limit_centsnumber
NULL
opening_balance_centsnumber
475941
account_idnumber · unique id
5
customer_idnumber · links to customers
3
account_typetext
credit_card
opened_atdate
2024-09-26
closed_attext
NULL
credit_limit_centsnumber
1020600
opening_balance_centsnumber
-339148
account_idnumber · unique id
6
customer_idnumber · links to customers
4
account_typetext
checking
opened_atdate
2023-07-18
closed_attext
NULL
credit_limit_centsnumber
NULL
opening_balance_centsnumber
155995
account_idnumber · unique id
7
customer_idnumber · links to customers
4
account_typetext
savings
opened_atdate
2024-04-20
closed_attext
NULL
credit_limit_centsnumber
NULL
opening_balance_centsnumber
1484759
account_idnumber · unique id
8
customer_idnumber · links to customers
5
account_typetext
checking
opened_atdate
2018-02-14
closed_attext
NULL
credit_limit_centsnumber
NULL
opening_balance_centsnumber
57994
account_idnumber · unique id
9
customer_idnumber · links to customers
6
account_typetext
checking
opened_atdate
2024-08-16
closed_attext
NULL
credit_limit_centsnumber
NULL
opening_balance_centsnumber
72360
account_idnumber · unique id
10
customer_idnumber · links to customers
7
account_typetext
checking
opened_atdate
2024-08-20
closed_attext
NULL
credit_limit_centsnumber
NULL
opening_balance_centsnumber
83275

first 10 of 2,109 rows · your queries use all of them

cards8 columns · 1,774 rows
card_idnumber · unique idaccount_idnumber · links to accountscard_typetextnetworktextlast4textissued_atdateexpires_ondatestatustext
11debitvisa19952024-09-062028-09-05active
22debitvisa32522025-06-112029-06-10active
33debitvisa12412024-07-132028-07-12active
45creditvisa30442024-09-262028-09-25active
56debitmastercard99452023-07-182027-07-17active
68debitvisa74432023-08-232027-08-22active
79debitvisa17162024-08-162028-08-15active
810debitmastercard33852024-08-202028-08-19active
911creditmastercard50202025-01-052029-01-04active
1012debitmastercard85912023-08-202027-08-19active
card_idnumber · unique id
1
account_idnumber · links to accounts
1
card_typetext
debit
networktext
visa
last4text
1995
issued_atdate
2024-09-06
expires_ondate
2028-09-05
statustext
active
card_idnumber · unique id
2
account_idnumber · links to accounts
2
card_typetext
debit
networktext
visa
last4text
3252
issued_atdate
2025-06-11
expires_ondate
2029-06-10
statustext
active
card_idnumber · unique id
3
account_idnumber · links to accounts
3
card_typetext
debit
networktext
visa
last4text
1241
issued_atdate
2024-07-13
expires_ondate
2028-07-12
statustext
active
card_idnumber · unique id
4
account_idnumber · links to accounts
5
card_typetext
credit
networktext
visa
last4text
3044
issued_atdate
2024-09-26
expires_ondate
2028-09-25
statustext
active
card_idnumber · unique id
5
account_idnumber · links to accounts
6
card_typetext
debit
networktext
mastercard
last4text
9945
issued_atdate
2023-07-18
expires_ondate
2027-07-17
statustext
active
card_idnumber · unique id
6
account_idnumber · links to accounts
8
card_typetext
debit
networktext
visa
last4text
7443
issued_atdate
2023-08-23
expires_ondate
2027-08-22
statustext
active
card_idnumber · unique id
7
account_idnumber · links to accounts
9
card_typetext
debit
networktext
visa
last4text
1716
issued_atdate
2024-08-16
expires_ondate
2028-08-15
statustext
active
card_idnumber · unique id
8
account_idnumber · links to accounts
10
card_typetext
debit
networktext
mastercard
last4text
3385
issued_atdate
2024-08-20
expires_ondate
2028-08-19
statustext
active
card_idnumber · unique id
9
account_idnumber · links to accounts
11
card_typetext
credit
networktext
mastercard
last4text
5020
issued_atdate
2025-01-05
expires_ondate
2029-01-04
statustext
active
card_idnumber · unique id
10
account_idnumber · links to accounts
12
card_typetext
debit
networktext
mastercard
last4text
8591
issued_atdate
2023-08-20
expires_ondate
2027-08-19
statustext
active

first 10 of 1,774 rows · your queries use all of them

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

settlements4 columns · 37,071 rows
settlement_idnumber · unique idauthorization_idnumber · links to authorizationssettled_atdate & timeamount_centsnumber
132025-01-23 01:12:537655
242025-01-30 13:04:516852
352025-01-30 17:41:215771
462025-02-11 06:57:343717
572025-02-11 19:25:534401
682025-02-20 03:08:189288
792025-03-02 17:28:416724
8102025-03-30 06:36:299131
9112025-04-02 19:51:0516129
10122025-04-04 01:55:5225236
settlement_idnumber · unique id
1
authorization_idnumber · links to authorizations
3
settled_atdate & time
2025-01-23 01:12:53
amount_centsnumber
7655
settlement_idnumber · unique id
2
authorization_idnumber · links to authorizations
4
settled_atdate & time
2025-01-30 13:04:51
amount_centsnumber
6852
settlement_idnumber · unique id
3
authorization_idnumber · links to authorizations
5
settled_atdate & time
2025-01-30 17:41:21
amount_centsnumber
5771
settlement_idnumber · unique id
4
authorization_idnumber · links to authorizations
6
settled_atdate & time
2025-02-11 06:57:34
amount_centsnumber
3717
settlement_idnumber · unique id
5
authorization_idnumber · links to authorizations
7
settled_atdate & time
2025-02-11 19:25:53
amount_centsnumber
4401
settlement_idnumber · unique id
6
authorization_idnumber · links to authorizations
8
settled_atdate & time
2025-02-20 03:08:18
amount_centsnumber
9288
settlement_idnumber · unique id
7
authorization_idnumber · links to authorizations
9
settled_atdate & time
2025-03-02 17:28:41
amount_centsnumber
6724
settlement_idnumber · unique id
8
authorization_idnumber · links to authorizations
10
settled_atdate & time
2025-03-30 06:36:29
amount_centsnumber
9131
settlement_idnumber · unique id
9
authorization_idnumber · links to authorizations
11
settled_atdate & time
2025-04-02 19:51:05
amount_centsnumber
16129
settlement_idnumber · unique id
10
authorization_idnumber · links to authorizations
12
settled_atdate & time
2025-04-04 01:55:52
amount_centsnumber
25236

first 10 of 37,071 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.

Big spenders for their state — SQL practice · Runtime