Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Average Department vs Enterprise SQL
00:00
5 left

Average Department vs Enterprise SQL

EasySQL · PostgreSQL

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
Interviewer

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