SQL Playground Mission: Channel Conversion Report
Rank marketing channels by purchase rate without dropping zero-conversion channels.
Conversion reports need a careful base. If you start from purchase events, channels with no purchases vanish. Starting from sessions and using a LEFT JOIN keeps every channel in view.
This mission also uses distinct counts because a session can contain more than one event row. The result is a clean channel report: total sessions, purchasing sessions, and purchase rate.
select base.segment,
count(distinct base.id) as total,
count(distinct event.id) filter (where event.name = 'target') as converted,
round(100.0 * converted / total, 1) as conversion_rate
from base
left join event on event.id = base.id
group by base.segmentSchema · Website AnalyticsTable · sessions7 columns · 30 rows
One row per visit. Anonymous visits have a null user_id; organic and direct visits have a null campaign_id.
SchemaTable · events4 columns · 39 rows
Funnel events (signup, add_to_cart, checkout, purchase). Only purchase events carry a value.
Return one row per channel with channel, sessions,purchasing_sessions, and purchase_rate. Sort by purchase rate descending, then channel.
- Columns: channel, sessions, purchasing_sessions, purchase_rate.
- Rows: one per channel (5 rows).
- Social has the highest purchase rate at 37.5%.