Spend 'utilities', premium: Apr 2025
Instructions
A client's spend is their transactions of the category 'utilities' (transactions.category, the amounts are negative) across all their accounts from April 1, 2025 to April 30, 2025 inclusive; the spend amount is the absolute value of the sum of amount of these transactions (−sum(amount)). For clients of the segment 'premium', for each city (clients.city), output city, clients (the number of all clients of the segment in the city, including those with no spend or even no accounts), spenders (the number of clients with at least one such spend), spend (the sum of their spend, 0 if there is none), spend_per_client (spend / clients) and spend_per_spender (spend / spenders; NULL if spenders = 0); round both averages to 2 decimal places. Sort by city.
Hints
Each next one is more detailed and costs more
Query
Result
Click Run to see the query result, or Check to submit your solution.
Dataset schema
Table relationships
- N:1Many-to-one
accounts.→client_id clients.id - N:1Many-to-one
transactions.→account_id accounts.id
Table data
Select a table in the diagram or list to view its rows.