Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
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
Sign up free to run your codeLog inLn 1
Run your query to see results here.