CS FundamentalsHardGATE CS · Amazon/Microsoft SDE MCQ

Table Emp(eid, name, mgr, dept, sal) rows: (1, 'Aru', NULL, 'D1', 90), (2, 'Bin', 1, 'D1', 60), (3, 'Cy', 1, 'D2', 70), (4, 'Dev', 2, 'D1', 60), (5, 'Eli', 2, 'D2', 40), (6, 'Fay', 3, NULL, 75), (7, 'Gus', 4, 'D1', 30). mgr refers to eid. What does this query return? SELECT COUNT(*) FROM Emp e WHERE sal > (SELECT AVG(sal) FROM Emp x WHERE x.dept = e.dept);

  1. A. 2
  2. B. 3
  3. C. 4
  4. D. 1

Correct answer: A. 2

D1 averages 60 (90, 60, 60, 30), so only Aru exceeds it; D2 averages 55, so Cy qualifies. For Fay, x.dept = NULL matches no row, the AVG is NULL and 75 > NULL is UNKNOWN, so the count is 2.

More DBMS and SQL questions

Exams that ask this topic