Management & CommerceHardBusiness analyst · SQL test

Table emp(id, name, dept, salary, mgr) has rows (1, Asha, Sales, 90, NULL), (2, Ravi, Sales, 60, 1), (3, Meena, Sales, 75, 1), (4, Kiran, Ops, 50, NULL), (5, Dev, Ops, 70, 4), (6, Neha, Ops, NULL, 4). What does SELECT SUM(COALESCE(salary, 0)) FROM emp WHERE dept = 'Ops' return, compared with SELECT SUM(salary) FROM emp WHERE dept = 'Ops'?

  1. A. 120 and NULL
  2. B. Both return 120
  3. C. 120 and 0
  4. D. NULL and 120

Correct answer: B. Both return 120

SUM already ignores NULLs, so SUM(salary) = 50 + 70 = 120; COALESCE turns Neha's NULL into 0 and also gives 120. COALESCE matters for AVG (60 vs 40) or row-level arithmetic, not for SUM.

More Operations, Supply Chain & Business Analytics questions

Exams that ask this topic