Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Optimize Dashboard Revenue Join Query
00:00
5 left

Optimize Dashboard Revenue Join Query

HardSQL · PostgreSQL

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
Interviewer

Your question is Optimize Dashboard Revenue Join Query. Start with the requirements and the five 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.