Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Aggregates Over Salaries

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

Your question is SQL Aggregates Over Salaries. Start with the requirements and the three 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

Swiggy's Business Analytics team needs a payroll snapshot for currently active employees. Write a PostgreSQL query that combines employee, department, and salary data to calculate salary statistics.

Requirements

  1. Include only employees whose employment_status is Active.
  2. Join employees to departments so that only employees assigned to a valid department are included.
  3. Preserve active employees even when their salary is missing, allowing PostgreSQL's aggregate functions to handle NULL values correctly.
  4. Return one row containing the total salary, minimum salary, and maximum salary.

Schema

employees
ColumnTypeDescription
employee_idPKINTUnique employee identifier
employee_nameVARCHAR(100)Employee's full name
department_idINTAssigned department identifier
employment_statusVARCHAR(20)Current employment status
departments
ColumnTypeDescription
department_idPKINTUnique department identifier
department_nameVARCHAR(100)Swiggy department name
employee_salaries
ColumnTypeDescription
employee_idPKINTEmployee identifier
monthly_salaryNUMERIC(12,2)Monthly salary in INR
Tablesemployeesdepartmentsemployee_salaries
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results