SQL Practice Logo

SQLPractice Online

Scenario SQL Question

Multiple CTEs — Department Productivity

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

Problem Statement

Use two CTEs — one for salary stats, one for project counts — then join them. Show department_id, department_name, avg_salary, total_projects, and productivity_ratio (total_projects / employee_count, 0 when no employees). Return rows ordered by department_name. Round avg_salary and productivity_ratio to 2 decimals.

Relevant Tables

departmentsemployeesprojects

SQL Concepts Used in This Scenario

Strengthen your understanding with these targeted learning topics: