Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Monthly Revenue Running Totals by Region

Medium
SQL & Data ManipulationWindow FunctionsRankingRunning TotalsAsked 1 times

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

You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.

Sign up freeI have an account
SELECT ...
FROM ...
JOIN ... ON ...
GROUP BY ...
HAVING ...
ORDER BY ... DESC;
Sign up to unlock solutions
NTT DATA Data Scientist Interview Questions
Next questions
Top Revenue Region by QuarterMediumairtelCompare Region Performance Across MonthsHardAHEADSQL Monthly Revenue by RegionMedium
PostgreSQL