Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL GROUP BY and HAVING
00:00
5 left

SQL GROUP BY and HAVING

EasySQL · PostgreSQL

Problem

Write a SQL query using GROUP BY and HAVING to find departments where the average employee salary is greater than a specific threshold.

Use the departments and employees tables. For this exercise, the threshold is 75000.

Output

  1. One row per qualifying department.
  2. Return department_name and average_salary, rounded to two decimal places.
  3. Sort by average_salary descending, then department_name ascending.

Schema

departments
ColumnTypeDescription
department_idPKINTUnique department identifier
department_nameVARCHAR(100)Department name
employees
ColumnTypeDescription
employee_idPKINTUnique employee identifier
employee_nameVARCHAR(100)Employee name
department_idINTEmployee department reference
salaryNUMERIC(12,2)Annual employee salary
Tablesdepartmentsemployees
Interviewer

Your question is SQL GROUP BY and HAVING. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.