Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Find Customers Above Department Average

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Find Customers Above Department Average. Start with the requirements and the two tables on the right.

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.

Problem

You are given customer spend data across departments. Write a SQL query that returns each customer whose total spend is above the average spend of customers in the same department.

Schema

departments
ColumnTypeDescription
department_idPKINTPrimary key for the department
department_nameVARCHAR(100)Human-readable department name
customers
ColumnTypeDescription
customer_idPKINTPrimary key for the customer
customer_nameVARCHAR(100)Customer name
department_idINTDepartment the customer belongs to
spendNUMERIC(12,2)Total spend for the customer
Tablescustomersdepartments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results