Show three per-user counters in one row
An analytics dashboard shows three numbers per user in a single row: how many views, how many purchases, and how many refunds they made. Without conditional aggregates you'd run three separate queries and stitch them together.
For every user, compute in one query the count of events of type view, purchase, and refund separately. Sort by user id.
Expected output sample
This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables.
| views | refunds | user_id | purchases |
|---|---|---|---|
| 2 | 0 | 1 | 2 |
| 3 | 0 | 2 | 0 |
| 1 | 1 | 3 | 1 |
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign in