SQL Problems


Finding Employees Who Have Worked on Multiple Projects

This technical problem deals with finding employees who have worked on multiple projects. A SQL query is provided that returns the names of all employees who have worked on at least two projects.

Problem

Write a SQL query that returns the names of all employees who have worked on at least two projects.
Example input:
EMPLOYEES
+----+----------+
| id | name |
+----+----------+
| 1 | John |
| 2 | Jane |
| 3 | Joe |
+----+----------+
PROJECTS
+----+--------------+
| id | name |
+----+--------------+
| 1 | Project A |
| 2 | Project B |
| 3 | Project C |
+----+--------------+
EMPLOYEE_PROJECTS
+----+-------------+-------------+
| id | employee_id | project_id |
+----+-------------+-------------+
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| 3 | 2 | 2 |
| 4 | 2 | 3 |
| 5 | 3 | 1 |
+----+-------------+-------------+
Example output:
+----------+
| name |
+---------- +
| John |
| Jane |
+----------+

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by AskAI
SELECT name
FROM EMPLOYEES
WHERE id IN (
    SELECT employee_id
    FROM EMPLOYEE_PROJECTS
    GROUP BY employee_id
    HAVING COUNT(*) >= 2
)

A.I. Evaluation of the Solution

The solution is complete and solves the problem. The approach is to first get all employees who have worked on at least two projects and then return the names of those employees.

Evaluated at: 2022-11-07 23:37:28