SQL Practice Logo

SQLPractice Online

Scenario SQL Question

Department Summary With a CTE

Build mastery in Ctes Window with this scenario-based SQL challenge and live execution support.

Problem Statement

Use a CTE to pre-compute department totals, then display each department with its headcount and total salary expense. Departments with no employees show 0. Return department_id, department_name, total_employees, total_salary_expense — ordered by total_salary_expense DESC, department_id.

Relevant Tables

departmentsemployees

SQL Concepts Used in This Scenario

Strengthen your understanding with these targeted learning topics: