CS FundamentalsVery hardTCS Digital · Infosys SP · GATE CS

Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4, 'Dev', 'Tech', NULL, 3), (5, 'Esha', NULL, 35, 3), (6, 'Farid', 'Tech', 70, 2). What does this query return?

Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4, 'Dev', 'Tech', NULL, 3), (5, 'Esha', NULL, 35, 3), (6, 'Farid', 'Tech', 70, 2). What does this query return?
SELECT name FROM Staff s
WHERE pay > (SELECT AVG(pay) FROM Staff t
             WHERE t.dept = s.dept);
  1. A. Bala, Esha
  2. B. Bala, Chitra, Farid
  3. C. Bala
  4. D. Chitra, Farid

Correct answer: C. Bala

Ops average = 47.5, so Bala (55) qualifies. Tech average ignores Dev's NULL: (70 + 70)/2 = 70, and nobody exceeds it. For Esha, t.dept = NULL matches nothing, the average is NULL and the comparison is unknown.

More DBMS and SQL questions

Exams that ask this topic