Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Query for Above-Average Salary

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

Your question is SQL Query for Above-Average Salary. 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

Dayforce workforce reporting needs to identify employees whose annual salary is above the company-wide average. Write a PostgreSQL query that returns these employees with their department information.

Requirements

  1. Calculate the average of all non-NULL values in employees.annual_salary.
  2. Return employees whose salary is strictly greater than that average.
  3. Include employees even when they have no department assignment, using a LEFT JOIN.
  4. Return results ordered from highest salary to lowest salary, with employee_id as a tie-breaker.

Schema

employees
ColumnTypeDescription
employee_idPKINTUnique employee identifier
employee_nameVARCHAR(100)Employee's full name
department_idINTReferences the employee's department
annual_salaryNUMERIC(10,2)Employee's annual salary
departments
ColumnTypeDescription
department_idPKINTUnique department identifier
department_nameVARCHAR(100)Department name
Tablesemployeesdepartments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results