Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 feedbackSuccess 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
Top Customers by Last-Quarter Spend
00:00
5 left

Top Customers by Last-Quarter Spend

MediumSQL · PostgreSQL

Problem

Write a PostgreSQL query to find the top three customers by total spend in the last completed quarter by joining customers and transactions. Return customer_id, customer_name, and total_spend, ordered by highest spend first. Assume CURRENT_DATE = '2024-08-15', so the target quarter is 2024-04-01 to 2024-06-30.

Schema

ColumnTypeDescription
customer_id INT PK
customer_name VARCHAR(100)
segment VARCHAR(50)
onboarded_at DATE
ColumnTypeDescription
transaction_id INT PK
customer_id INT FK
transaction_date DATE
amount DECIMAL(10,2)
cost_center VARCHAR(50)

Representative Rows

customers
101Acme HealthEnterprise2023-11-10
102BluePeak RetailMid-Market2024-01-05
104Delta ManufacturingEnterprise2023-09-15
transactions
10021012024-04-01300.00SaaS
10061022024-05-181200.00SaaS
10101042024-06-251600.00Labor
Tablescustomerstransactions
Interviewer

Your question is Top Customers by Last-Quarter Spend. Start with the requirements and the two 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.