One query: by type, by user, and grand total
The dashboard wants three slices in a single result: event counts by type, event counts by user, and the grand total across all events. Running three queries and stitching them via union is ugly and inefficient: one grouping over several sets of columns delivers everything in a single pass. Show event type, user id, and event count — for the «by type only», «by user only», and «grand total» slices. In the by-type slice the user id is empty; in the by-user slice the type is empty; in the grand-total row both are empty. 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 | kind | user_id |
|---|---|---|
| 2 | click | NULL |
| 8 | page | NULL |
| 4 | NULL | 1 |
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign in