Paid above the department average

subqueries

Paid above the department average

Google SQL Interview Question

Google's people analytics team is reviewing pay and wants to see who earns more than the typical salary in their own department.

List the name, department and salary of every employee who earns more than the average salary of their own department.

Asked of

  • Data Analyst
  • Data Scientist
  • Analytics Engineer
  • Data Engineer

employeesTable16 rows

Column NameType
employee_idBIGINT
nameVARCHAR
departmentVARCHAR
salaryBIGINT
manager_idBIGINT
hire_dateDATE

employeesExample Input

employee_idnamedepartmentsalarymanager_idhire_date
1Ravi KumarExecutive240000NULL2018-01-15
2Mei LinEngineering18500012018-06-04
3Sofia RossiEngineering14200022019-02-18
4James ParkEngineering12800022019-09-02
7Diego AlvarezAnalytics16800012018-10-22
8Hannah WeberAnalytics13400072020-01-13

Example Output

namedepartmentsalary
Diego AlvarezAnalytics168000
Mei LinEngineering185000

Explanation

Engineering's three salaries average about 151,667, and only Mei Lin, at 185,000, is above that. In Analytics, Diego Alvarez earns more than the department average of 151,000. Ravi Kumar is the only person in Executive, so that salary equals the department average and is not above it.

The example above is a small slice of the data. Your query runs against the full tables.