Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL for Usage and Revenue Growth
00:00
5 left

SQL for Usage and Revenue Growth

MediumSQL · PostgreSQL

Problem

Write a SQL query to analyze enterprise customer usage by account, region, and month, and identify the top accounts driving revenue growth.

Use the provided accounts and monthly_usage tables. Calculate month-over-month revenue growth for accounts with a prior month, and return the two highest-growth accounts per region and month when growth is positive.

Output

  1. One row per qualifying account and month with region, usage_month, account_id, account_name, revenue, usage_units, revenue_growth_amount, revenue_growth_pct, and region_rank.
  2. Order by region, usage_month, region_rank, and account_id.

Schema

accounts
ColumnTypeDescription
account_idPKINTUnique enterprise account identifier
account_nameVARCHAR(100)Enterprise account name
regionVARCHAR(50)Account geographic region
segmentVARCHAR(50)Enterprise customer segment
monthly_usage
ColumnTypeDescription
usage_idPKINTUnique usage record identifier
account_idINTReferenced enterprise account
usage_monthDATEFirst day of the usage month
usage_unitsINTConsumed service usage units
revenueNUMERIC(12,2)Revenue attributed to the usage record
Tablesaccountsmonthly_usage
Interviewer

Your question is SQL for Usage and Revenue Growth. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.