Analytical SQL · SQL problem

Departments Paid Above the Company Average

A free sql problem from the CTEs and Recursive Queries skill. Read it here, then solve it in the app.

  • Easy
  • SQL problem
  • Free

The problem

HR wants to know which departments pay above the company as a whole. Return every department whose average salary is higher than the average salary of all employees:

columnmeaning
departmentthe department
employeeshow many people work in it
avg_salaryits average salary, rounded to a whole number

Sort by avg_salary from highest to lowest, then by department.

Constraints

The company average is over all employees - not an average of the department averages.

How it's graded

  • Your SQL runs on PostgreSQL 18. Run compares your rows with the expected rows on the sample data; Submit runs it against hidden datasets built to catch the classic mistakes.
  • Stuck? Hints come in four steps, from a nudge to a code skeleton, each costing part of the points.

More problems in CTEs and Recursive Queries

Write the query Departments Paid Above the Company Average free

No card needed. Lessons, practice questions and easy problems are free forever.

Free plan, no card · 7-day Pro trial · Cancel anytime