Dept Salary Comparison

4pts
Google

Problem Statement

Google HR wants to identify high-earners relative to their peers. Your task is to find all employees who earn more than the average salary of their department.

Rules:

  • Output columns: employee_id, name, salary, department_id.
  • Results must be sorted by employee_id in ascending order.
Tests your understanding of
Window Functions, Subqueries and Aggregation

Input Tables

Employees
employee_id(INTEGER)name(VARCHAR)salary(INTEGER)department_id(INTEGER)
1Alice900001
2Bob700001
3Charlie800002
4David1100002
5Eve1050002
Departments
department_id(INTEGER)dept_name(VARCHAR)
1Engineering
2Marketing
Bonus_Log
employee_id(INTEGER)bonus_amount(INTEGER)
15000

Expected Output

employee_id(INTEGER)name(VARCHAR)salary(INTEGER)department_id(INTEGER)
1Alice900001
4David1100002
5Eve1050002

Tags

MediumWindow FunctionsSubqueriesAggregation
20-25 min
51%

Hints