Accounts: 6+ expenses in the category health
Level: JuniorTopic: Aggregates, GROUP BY and HAVING50 XP
Instructions
Among the transactions of the category 'health' with a negative amount of at least 800 in absolute value (amount at most -800), compute by account (account_id): tx_cnt, the number of such transactions, and avg_spent, the average expense as a positive number (minus the average amount), rounded to 2 decimal places. Select account_id, tx_cnt, avg_spent; keep the accounts where tx_cnt is at least 6. 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
Exactly oneZero or oneZero or more
Table relationships
- N:1Many-to-one
accounts.→client_id clients.id - N:1Many-to-one
transactions.→account_id accounts.id
Table data
PostgreSQL
Select a table in the diagram or list to view its rows.