Select the correct SQL query that returns all students whose results are greater than the
Select the correct SQL query that returns all students whose results are greater than the
average result of their respective departments.
Show answerHide answer
Correct answer: (D) SELECT stu_id FROM student s WHERE result > (SELECT AVG(result) FROM student WHERE dept_id = s.dept_id);
Explanation
To compare each student with their own department's average, the subquery must be correlated: WHERE dept_id = s.dept_id links it to the outer row. Option A's subquery returns several averages, and B uses an aggregate in WHERE, which is not allowed.