#784

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.

ntypeuser_id
12purchaseNULL
6refundNULL
10viewNULL

Your query result will appear here