Intern Stipend by Department and Start Date
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:
dept_name(varchar(50))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
Similar problems
- Internship Offers by Department and SalaryMedium
- Internship Performance by DepartmentMedium
- Internship Offers by Company and DepartmentMedium
- Find Departments with Above Average Salary SpendingMedium
- Find Interns with Above Average SalaryMedium
- Students with Above Average GPA in Their DepartmentMedium
More in: SQL and Databases problems
-- Calculate total stipends by department for March 2025 starters
SELECT
Your query runs on the example tables shown with the problem, then on hidden datasets when you submit.
Write standard SQL. MySQL habits work too: IFNULL, IF, YEAR(), DATE_FORMAT, GROUP_CONCAT, `backticks` and LIMIT 5, 10. It runs on PostgreSQL, so integer division keeps whole numbers (5 / 2 = 2): write 5.0 / 2 for 2.5.