Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL Inner Join and Aggregate
00:00
5 left

SQL Inner Join and Aggregate

MediumSQL · PostgreSQL

Problem

Write a SQL query to retrieve data from two tables using an inner join and aggregate the results.

Use the provided departments and employees tables. Return one row for each department with at least one matching employee.

Output

  1. Return department_name, employee_count, and total_salary.
  2. Count employees, sum non-null salaries, and exclude departments without matching employees.
  3. Order by total_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_idINTReferenced department identifier
salaryINTEmployee salary
Tablesdepartmentsemployees
Interviewer

Your question is SQL Inner Join and Aggregate. 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.