Find employees who are working on more than two projects.
💡 Model Answer
To find employees assigned to more than two projects, you can use a GROUP BY with a HAVING clause. Assuming you have an employees table (employees) and a junction table (employee_projects) that links employees to projects, the query would look like this:
SELECT e.employee_id,
e.first_name,
e.last_name
FROM employees e
JOIN employee_projects ep ON e.employee_id = ep.employee_id
GROUP BY e.employee_id, e.first_name, e.last_name
HAVING COUNT(DISTINCT ep.project_id) > 2;
Explanation:
Complexity: The query scans the employee_projects table once (O(n)) and performs a hash/grouping operation. The overall time is linear in the number of rows in employee_projects, and the memory usage is proportional to the number of distinct employees. This is efficient for typical relational databases and scales well with large datasets.
Sign in to unlock the rest of this answer
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500