Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Monthly Revenue Running Totals by Region

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

Your question is Monthly Revenue Running Totals by Region. 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 customer, region, and invoice data from an NTT DATA reporting environment. Write a PostgreSQL query that returns monthly revenue by customer and region, calculates a running total of monthly revenue for each customer within their region, and ranks customers within each region and month based on that month’s revenue. Exclude invoices with NULL revenue, and show the month in YYYY-MM format.

Schema

regions
ColumnTypeDescription
region_idPKINTPrimary key for the region
region_nameVARCHAR(50)Name of the region
customers
ColumnTypeDescription
customer_idPKINTPrimary key for the customer
customer_nameVARCHAR(100)Customer name
region_idINTRegion assigned to the customer
invoices
ColumnTypeDescription
invoice_idPKINTPrimary key for the invoice
customer_idINTCustomer tied to the invoice
invoice_dateDATEDate of the invoice
revenueDECIMAL(10,2)Revenue amount for the invoice
Tablesregionscustomersinvoices
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results