Intern Stipend by Department and Start DateMedium

Intern Stipend by Department and Start Date

MediumSQLPractice library · +20 XPmulti-table joinssqlaggregation

UptoSkills Arena needs to track intern stipends to manage its budget. Given intern and department information, find the total stipend paid out by each department for interns who started in March 2025.

Tables:

  • departments: dept_id (integer, PK), dept_name (varchar(50))
  • interns: intern_id (integer, PK), dept_id (integer, FK to departments), stipend (numeric(10,2)), start_date (date)

Return the department name and the total stipend for that department for interns starting in March 2025. If a department has no interns starting in March 2025, it should not appear in the results. Handle NULL stipends by excluding them from the sum. The results should be ordered by department name.

Output Columns:

  1. dept_name (varchar(50))
  2. total_stipend (numeric(10,2))

Tables

CREATE TABLE departments (
  dept_id integer PRIMARY KEY,
  dept_name varchar(50) NOT NULL
);

CREATE TABLE interns (
  intern_id integer PRIMARY KEY,
  dept_id integer NOT NULL,
  stipend numeric(10,2),
  start_date date NOT NULL
);

Example data

INSERT INTO departments (dept_id, dept_name) VALUES
(1, 'Engineering'),
(2, 'Marketing'),
(3, 'Human Resources'),
(4, 'Finance');

INSERT INTO interns (intern_id, dept_id, stipend, start_date) VALUES
(101, 1, 5000.00, '2025-03-15'),
(102, 1, 5500.00, '2025-03-20'),
(103, 2, 4500.00, '2025-03-10'),
(104, 1, 6000.00, '2025-04-01'),
(105, 3, 4000.00, '2025-03-05'),
(106, 2, 4800.00, '2025-04-10'),
(107, 1, 5200.00, '2025-03-25'),
(108, 4, 5000.00, '2025-03-18');

Your query is also checked on hidden datasets with different data.

Hints