HomeInterview QuestionsWhat is the error in the following SQL query that …

What is the error in the following SQL query that finds employees working on projects greater than or equal to the average number of projects per employee?

🟢 Easy Debugging Junior level
1Times asked
Jul 2026Last seen
Jul 2026First seen

💡 Model Answer

The query contains a syntax error caused by an extra comma between the column alias and the aggregate function in the SELECT list. In SQL you must separate columns with commas, but you cannot place a comma between a column name and an aggregate function that is part of the same SELECT clause. The correct syntax is: SELECT e.last_name, COUNT(ep.project_id) AS project_count FROM employees e JOIN employee_projects ep ON e.id = ep.employee_id GROUP BY e.last_name HAVING COUNT(ep.project_id) >= (SELECT AVG(project_count) FROM (SELECT COUNT(*) AS project_count FROM employee_projects GROUP BY employee_id) AS sub); The key point is to remove the stray comma and ensure the aggregate is part of the same SELECT expression.

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