Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Average Department vs Enterprise SQL

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

Your question is Average Department vs Enterprise SQL. 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

Tavant leadership wants a salary comparison view for workforce planning across its engineering and delivery teams. Write a PostgreSQL query that shows each department's average salary alongside the average salary across the entire enterprise.

Requirements

  1. Return every department, including departments with no assigned employees.
  2. Calculate the average non-null salary for each department.
  3. Calculate the overall average non-null employee salary once and display it beside every department.
  4. Round both averages to two decimal places and order the results by department ID.

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 identifier
salaryNUMERIC(10,2)Annual employee salary
Tablesdepartmentsemployees
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results