Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Optimize Dashboard Revenue Join Query

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

Your question is Optimize Dashboard Revenue Join Query. Start with the requirements and the five 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 a dashboard query that joins several large tables to show monthly revenue by account, product, and region. Your task is to write a PostgreSQL query that returns the final dashboard result efficiently, while preserving correct totals and ranking the top products within each month. Assume the source tables are large enough that repeated scans and unnecessary row expansion matter.

Schema

accounts
ColumnTypeDescription
account_idPKINTPrimary account identifier
account_nameVARCHAR(255)Customer account name
region_idINTRegion assigned to the account
regions
ColumnTypeDescription
region_idPKINTPrimary region identifier
region_nameVARCHAR(100)Human-readable region name
products
ColumnTypeDescription
product_idPKINTPrimary product identifier
product_nameVARCHAR(255)Product name shown in the dashboard
orders
ColumnTypeDescription
order_idPKINTPrimary order identifier
account_idINTAccount that placed the order
order_dateDATEOrder date
order_items
ColumnTypeDescription
order_item_idPKINTPrimary line-item identifier
order_idINTRelated order identifier
product_idINTRelated product identifier
quantityINTUnits sold on the line item
unit_priceNUMERIC(10,2)Price per unit at the time of sale
Tablesaccountsregionsproductsordersorder_items
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results