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 for Fay? SELECT name, AVG(sal) OVER (PARTITION BY dept) FROM Emp;

  1. A. NULL, since her dept is NULL
  2. B. about 60.71, the overall average
  3. C. 75
  4. D. 60, the D1 average

Correct answer: C. 75

PARTITION BY puts all NULL keys into one partition, just as GROUP BY does. Fay is the only row with a NULL dept, so her partition average is her own 75.

More DBMS and SQL questions

Exams that ask this topic