web_sessions (session_id, channel, device, revenue) holds one row per site session. Some sessions arrived with no tracked channel: their channel is NULL.
Build one result with three kinds of rows, and nothing else:
- •one row per channel — sessions with no channel form their own row, shown as
channel = 'unknown'; device is NULL on these rows; - •one row per device —
channel is NULL on these rows; - •one total row —
channel and device both NULL.
Each row has the number of sessions and their total revenue, and a grouping_level column saying which kind of row it is: 'channel', 'device' or 'total'. Don't break revenue down by channel *and* device together.
Columns: grouping_level, channel, device, sessions, revenue. Sort by grouping_level, then channel, then device.