Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Customer Cohorts by Revenue

EasySQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Top Customer Cohorts by Revenue. Start with the requirements and the one table on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

You are given a table of customer activity from PNC digital marketing campaigns. Write a SQL query to identify the top-performing customer cohorts, where a cohort is defined by cohort_month. Return each cohort's total revenue and customer count, sorted from highest total revenue to lowest, and show only the top 3 cohorts.

Because this is an easy SQL exercise, solve it using only a single table with aggregation, sorting, and limiting.

Schema

pnc_customer_activity
ColumnTypeDescription
activity_idPKINTUnique activity row identifier
customer_idINTCustomer identifier
cohort_monthVARCHAR(7)Customer acquisition cohort in YYYY-MM format
channelVARCHAR(30)Marketing acquisition channel
revenueDECIMAL(10,2)Revenue attributed to the activity
activity_dateDATEDate of customer activity
Tablespnc_customer_activity
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results