Question 10Asked in DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 3 (5:00 PM)

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.
  1. ASELECT stu_id             FROM student             WHERE result > (SELECT AVG(result) FROM student GROUP BY dept_id);
  2. BSELECT stu_id             FROM student             WHERE result > AVG(result) GROUP BY dept_id;
  3. CSELECT stu_id             FROM student s             WHERE result > (SELECT AVG(s.result) FROM student);
  4. DSELECT stu_id              FROM student s              WHERE result > (SELECT AVG(result) FROM student WHERE dept_id = s.dept_id);
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.

From DSSSB TGT Computer Science PYQ (Technical), 12 Sep 2025, Shift 3 (5:00 PM)

This is question 10 of DSSSB TGT Computer Science PYQ (Technical), 12 Sep 2025, Shift 3 (5:00 PM). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.