CS FundamentalsHardGATE CS · SQL

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 SUM(NULLIF(pay, 70)), COUNT(CASE WHEN pay > 50 THEN 1 END)
FROM Staff;
  1. A. 200, 3
  2. B. 130, 3
  3. C. 130, 6
  4. D. 270, 3

Correct answer: B. 130, 3

NULLIF turns both 70s into NULL, so SUM adds 40 + 55 + 35 = 130. A CASE with no ELSE yields NULL for non-matching rows, and COUNT skips NULLs: only Bala, Chitra and Farid count.

More DBMS and SQL questions

Exams that ask this topic