Question discussion

Select the correct SQL query that returns all students whose results are greater than the average result of their respective departments.

359014Medium DSSSB TGT Computer Science 0 replies 0 views
0
Select the correct SQL query that returns all students whose results are greater than the average result of their respective departments.
  • ASELECT stu_id FROM student WHERE result > (SELECT AVG(result) FROM student GROUP BY dept_id);
  • BSELECT stu_id FROM student WHERE result > AVG(result) GROUP BY dept_id;
  • CSELECT stu_id FROM student s WHERE result > (SELECT AVG(s.result) FROM student);
  • DSELECT stu_id FROM student s WHERE result > (SELECT AVG(result) FROM student WHERE dept_id = s.dept_id);
Correct answer: D

Explanation

A correlated subquery compares each student's result with the average of the same department. Only option 4 uses WHERE dept_id = s.dept_id for this.

Discussion 0

Nobody has replied yet. Start the discussion!