RienSQL
TASK #198 · Medium

The whole department headcount is counted instead of the needed part

Your brief
The report should show how many employees in each department have a manager. It returns as many departments as the company has, but the numbers are too high: they also count employees who have no manager.

For some employees the manager_id column holds nothing.

Output department_id and employees_with_manager (number of employees in the department who have a manager).
Expected columnsdepartment_id employees_with_managerCompany
SQL editor
SQLite
Ctrl / ⌘ + ↵
Result

Write a query and run it to see the results.

Schema
departmentsid, name
employeesid, name, department_id, manager_id, salary, hired_at
customersid, name, registered_at
ordersid, customer_id, employee_id, amount, created_at
loginsuser_id, logged_at