KatInterview

Compare Acquisition Channels by Spend, Retention, and Early Revenue

SQL & DataModel answer
MediumModel answerSQL & Datawindow-functionscohort-analysisaggregation

Last updated

Write SQL to profile marketing channels across four dimensions: user counts, top spenders, cohort retention, and 90-day ARPU.

Channel Performance Analysis

An e-commerce company tracks how users arrive on the platform and what they buy afterward. You have two tables.

signups

user_idchannelsignup_date
101organic2023-01-05
102paid_search2023-01-06
103social_media2023-01-08

orders

order_iduser_idamountorder_date
900110145.502023-01-10
900210119.002023-02-05
900310260.002023-02-12
900410330.002023-03-01

The growth team wants to understand which channels bring in the most valuable users. Write SQL to answer each of the following questions. For each part, state any assumptions you make before showing the query.

Part 1 — Channel size Return each channel alongside the number of distinct users who signed up through it.

Part 2 — Top spenders per channel For each channel, find the three highest-spending users and show their total spend. Explain how you handle ties.

Part 3 — Cohort retention Group users by the calendar month they signed up. For each cohort, calculate the percentage who placed at least one order in any later calendar month. A purchase in the same month as signup does not count as retention.

Part 4 — Early revenue by channel For each channel, compute average revenue per user (ARPU) using only orders placed within 90 days of a user's signup date. Identify the channel with the highest ARPU. Include users who placed no orders (they contribute 0 to the average).

You may use CTEs, window functions, DATE_TRUNC, and INTERVAL syntax. A Python/pandas sketch for any one part is a bonus.

Hints

Hint 1

Start every part by joining signups to orders with a LEFT JOIN so users who never ordered still appear in aggregations. Moving date-range conditions into the ON clause instead of WHERE preserves those zero-revenue users.

Hint 2

For Part 2, aggregate to one row per user before ranking. Applying RANK() directly on the orders table gives one row per order, not per user. Decide between RANK (keeps all ties), ROW_NUMBER (exactly 3, needs a tiebreaker), and DENSE_RANK (top 3 distinct spend values), and say which you chose and why.

Hint 3

For Part 3, the retention denominator is all users in the cohort, not just those who bought something. Use DATE_TRUNC to align both signup and order dates to month boundaries, then compare months with > rather than >= to exclude the signup month itself.