Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Customers by Last-Quarter Spend

Medium
MediumSQL & Data ManipulationDate FunctionsJoinsAggregations
Asked 1mo ago|
Mutual of Omaha
Mutual of Omaha
Asked 11 times

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
Practicing as: Customer Success Engineer interview at Apptio

Hi, I'll play your Apptio interviewer for the Customer Success Engineer role. Candidates describe these interviews as often stressful and moderately difficult, so expect me to be direct and to the point. Take your time with the question above and answer like we're in the room.

Take this as a live interview session →

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
Hewlett Packard Enterprise | HPE Consultant Interview QuestionsFreshworks Business Analyst Interview QuestionsStaples India Data Analyst Interview QuestionsBNY Data Scientist Interview QuestionsMutual of Omaha Software Engineer Interview Questions
Next questions
FinacleTop Customers by SpendMediumThe Church of Jesus Christ of Latter-day SaintsRank Customer Spend by DepartmentHardSignifydTop Customers by Monthly SpendMedium