CS FundamentalsModerateTCS 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 SUM(CASE WHEN pay >= 55 THEN 1 ELSE 0 END),
       SUM(CASE WHEN pay < 55 THEN 1 ELSE 0 END)
FROM Staff;
  1. A. 3, 2
  2. B. 3, 3
  3. C. 3, 2, 1
  4. D. 4, 2

Correct answer: A. 3, 2

Bala, Chitra, Farid have pay ≥ 55; Anu and Esha are below. Dev's NULL makes both conditions UNKNOWN, so both CASEs fall to ELSE 0 — his row is counted in neither.

More DBMS and SQL questions

Exams that ask this topic