Calculate metrics based on a few tables, doing some joins and stuff.
Write a SQL query that returns the requested metrics from the provided tables.
Output
- One row per requested entity at the required grain.
- Include only the columns specified in the schema and alias them exactly as required.
- Sort the result in the required order, with any tie-breakers applied consistently.
Output details
- Return columns
department_name, employee_count, completed_project_count, and total_hours in that order.
- Return every department, including departments with no employees, projects, or recorded hours.
- Count each employee and project ID once, counting projects only when
status equals completed.
- Use
0 when a department has no recorded hours.
- Sort ascending alphabetically by
department_name.