Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rank Customers by Monthly Usage

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

Your question is Rank Customers by Monthly Usage. 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

Write a SQL query to rank customers by monthly usage within each region at Viasat.

Use the provided customer and usage data. Include only customers with an assigned region and recorded usage, and treat a month as the calendar month of each usage record.

Output

  1. One row per customer and calendar month.
  2. Columns: region, usage_month, customer_id, customer_name, monthly_usage, and usage_rank.
  3. Rank customers within their region and month by monthly usage descending. Ties share a rank.
  4. Sort by region, usage_month, usage_rank, and customer_id.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer display name
regionVARCHAR(50)Assigned Viasat service region
usage_records
ColumnTypeDescription
usage_idPKINTUnique usage record identifier
customer_idINTCustomer associated with the usage record
usage_dateDATEDate on which usage occurred
usage_unitsNUMERIC(12,2)Usage amount recorded for the customer
Tablescustomersusage_records
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results