Black Afgano
Просветленный
(22302)
3 года назад
SELECT project_name, r.roles_count
FROM projects AS p
JOIN
(
SELECT project_id, COUNT (DISTINCT role) AS roles_count
FROM employees
GROUP BY project_id
) r ON p.project_id = r.project_id
ORDER BY 2;
Или ещё вот так
SELECT p.project_name, COUNT (DISTINCT role) AS roles_count
FROM employees as r
GROUP BY project_id
JOIN projects p
ON r.project_id = p.project_id
ORDER BY 2;