Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rank Customer Segments by Revenue

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

Your question is Rank Customer Segments by Revenue. Start with the requirements and the three tables 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 signup, account, and payment data from a B2B SaaS product. Write a SQL query to identify the highest-performing customer segments based on both revenue and signup-to-paid conversion. Treat a customer as converted if they have at least one successful payment within 30 days of signup. Return each segment's total customers, converted customers, conversion rate, total revenue from successful payments, and a rank ordered by highest revenue.

Use the segmentation dimensions already stored on the customer record, and only include segments with at least 2 customers.

Schema

rippling_customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
company_nameVARCHAR(100)Customer company name
company_size_segmentVARCHAR(20)Segment based on employee count
regionVARCHAR(20)Customer geographic region
signup_dateDATEDate the customer signed up
rippling_accounts
ColumnTypeDescription
account_idPKINTUnique billing account identifier
customer_idINTCustomer associated with the account
plan_nameVARCHAR(30)Subscribed Rippling plan
account_statusVARCHAR(20)Current billing account status
rippling_payments
ColumnTypeDescription
payment_idPKINTUnique payment identifier
account_idINTBilling account tied to the payment
payment_dateDATEDate the payment was processed
amount_usdDECIMAL(10,2)Payment amount in USD
payment_statusVARCHAR(20)Payment outcome
Tablesrippling_customersrippling_accountsrippling_payments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results