Get three breakdowns in a single query
The dashboard needs a single result with three slices at once: event counts by event type, event counts by user, and the grand total over all events. Running three queries and stitching them via union is ugly and inefficient: a single query with grouping over multiple sets of columns handles it. Show the event type, the user id, and the count of events — for the «by type only», «by user only», and «grand total» slices. Sort by event type (empty values last), then by user id (empty values last too).
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.
| n | type | user_id |
|---|---|---|
| 12 | purchase | NULL |
| 6 | refund | NULL |
| 10 | view | NULL |
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign in