Top 2 spending categories: Новосибирск, vip, Feb–Apr 2025
Instructions
Spending is transactions (transactions) with amount < 0 and tx_time on or after February 1, 2025 and strictly before May 1, 2025, across all of the client's accounts (including the category transfer); the spending in a category is the sum of -amount. Consider clients from the city 'Новосибирск' with the segment 'vip'; clients and categories without spending in this period are not considered. For each client, rank the categories by spending descending with ROW_NUMBER(); for equal spending the category whose name comes earlier alphabetically (the smaller category value) gets the better place. Output the 2 categories with the best places for each client (if the client has fewer categories, output all of them). Columns: client_id, category, spent, place. Row order does not matter.
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.