← Recursive CTEs

Client 209 shopping spend by week, from September 15, 2025

Level: Middle100 XP

Instructions

Build a series of 12 consecutive weeks, the first starting on Monday, September 15, 2025 and the last on Monday, December 1, 2025; a week is 7 days from Monday to Sunday inclusive. For each week, count the transactions of the category 'shopping' across all accounts of the client with client_id = 209: tx_cnt (their number) and spent (the sum of absolute values of amount; all transactions of this category are debits with a negative amount). Output weeks without such transactions with tx_cnt = 0 and spent = 0. Output week_start (type date), tx_cnt, spent. Sort by week_start ascending.

Hints

Each next one is more detailed and costs more

Log in to open hints

Query

Result

Click Run to see the query result, or Check to submit your solution.

Dataset schema

accounts.client_id (0…N) ↔ clients.id (1…1)transactions.account_id (0…N) ↔ accounts.id (1…1)accountsPKidintegerFKclient_idintegerclientsPKidintegertransactionsPKidintegerFKaccount_idinteger
Exactly oneZero or oneZero or more
Table relationships
  • N:1Many-to-oneaccounts.client_id → clients.id
  • N:1Many-to-onetransactions.account_id → accounts.id

Table data

PostgreSQL

Select a table in the diagram or list to view its rows.

Dataset schema