Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Customer Usage Growth Quartile

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

Your question is Top Customer Usage Growth Quartile. Start with the requirements and the two 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 customer account records and monthly Google Cloud usage data. Write a SQL query to find the customers in the top 10% of usage growth during the last completed quarter. Define growth as the difference between total usage in the last completed quarter and total usage in the quarter immediately before it. Exclude any account that churned within 30 days of signup. Return each qualifying customer's ID, name, prior-quarter usage, last-quarter usage, absolute growth, and percentile bucket, ordered by growth descending.

Assume the analysis date is 2024-10-15, so the last completed quarter is 2024-07-01 to 2024-09-30 and the prior quarter is 2024-04-01 to 2024-06-30.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer account name
signup_dateDATEDate the customer account was created
churn_dateDATEDate the customer churned, if applicable
account_tierVARCHAR(20)Customer contract tier
monthly_usage
ColumnTypeDescription
usage_idPKINTUnique usage record identifier
customer_idINTCustomer linked to the usage record
usage_monthDATEMonth of usage, stored as the first day of the month
product_nameVARCHAR(100)Google product associated with the usage
usage_unitsINTMeasured monthly usage units
Tablescustomersmonthly_usage
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results