Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rank Customer Spend by Department

Hard
HardSQL & Data ManipulationWindow FunctionsRankingAsked 3 times

Problem

Write a PostgreSQL query that ranks customers by total completed spend within each Apptio Cost Transparency department. Include customers with no completed purchases, treat NULL amounts as 0, and return department_name, customer_name, total_spend, and spend_rank.

Schema

departments
ColumnTypeDescription
department_id
department_name
customers
ColumnTypeDescription
customer_id
customer_name
department_id
purchases
ColumnTypeDescription
purchase_id
customer_id
amount
status
purchase_date

Representative Rows

customers
101Alice Chen1
105Evan Lee3
purchases
1001101300completed2024-02-10
1008105completed2024-02-03
departments
1FinOps
3CloudOps
Practicing as: Financial Analyst interview at The Church of Jesus Christ of Latter-day Saints

Hi, I'll play your The Church of Jesus Christ of Latter-day Saints interviewer for the Financial Analyst role. Candidates describe these interviews as mostly positive and moderately difficult, so expect me to be friendly and conversational. 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
T-rex Interview QuestionsT-rex Data Scientist Interview QuestionsThe Church of Jesus Christ of Latter-day Saints Financial Analyst Interview QuestionsTop 50 Ranking Interview QuestionsApptio Customer Success Engineer Interview Questions
Next questions
ApptioFind Customers Above Department AverageMediumApptioTop Customers by Last-Quarter SpendMediumRipplingCompare Department Spend to BudgetMedium