runtime
71 / 88

task Segmentation & ranking · hard

Checkout review 5: prioritize channel fixes

Prioritize channels by unrecovered abandoned sessions. For each session’s first-touch channel, return sessions, abandoned_sessions, recovered_sessions, unrecovered_sessions and priority_rank.

what to return

Columns
channelsessionsabandoned_sessionsrecovered_sessionsunrecovered_sessionspriority_rank in this order
Rows
4 rows · in the order asked
Watch for
This stage starts from the original event tables in a fresh database. Recompute any intermediate results; nothing is carried over from earlier stages.
Deduplicate globally by event_key, keeping the smallest id; a retry may have a conflicting payload.
Use (occurred_at, id) as the total event order; equal timestamps follow id order. All times are UTC.
A shopper starts a session at the first canonical event or after a gap strictly greater than 30 minutes from their previous canonical event. Exactly 30 minutes stays in the same session; midnight alone does not split it.
Session numbers start at 1 per shopper and include every event type, including heartbeat and purchase-only sessions.
A converted session has a view → checkout → purchase in that order, with all three events for the same shopper/cart within the session. Use the total event order. No extra view-to-purchase time limit applies.
Abandoned means the session has checkout but no full ordered conversion. Recovered means it has a same-cart purchase in a strictly later session within 24 hours (inclusive) of any checkout in the abandoned session.
Count each abandoned session at most once in recovery, even with several purchases. unrecovered_sessions = abandoned_sessions − recovered_sessions.
Keep all first-touch channels, including zeros. Use dense descending rank of unrecovered_sessions, with ties sharing rank. Order by priority_rank, then channel.
Skill
Translate the connected review into a channel-level prioritization table. Refresher: Sessionize an event stream →

expected result

Your query should return exactly these columns and values. Run it and compare.

expected result4 rows · in this order
channelsessionsabandoned_sessionsrecovered_sessionsunrecovered_sessionspriority_rank
social42021
direct31012
email62112

first 3 of 4 rows

data you can query

Sample rows from each table. Each column shows its type underneath; → marks a link to another table.

market_web_events7 columns · 38 rows
idinteger · keyevent_keytextshopper_idinteger → shoppersoccurred_attextevent_typetextchanneltextcart_idtext
1a112025-05-01 09:00:00viewemailA
2a212025-05-01 09:05:00checkoutdirectA
3a312025-05-01 09:10:00purchasedirectA
4a312025-05-01 09:10:00purchasedirectA
5b112025-05-01 10:00:00viewsearchB

showing 5 of 38 rows

solution.sql
 

Hints and the answer are always available. Using them counts the question as solved with help.