Management & CommerceHardBusiness analyst · SQL test

Using table v (where Goa's only row has amt NULL), what do SELECT SUM(amt) FROM v WHERE city = 'Goa' and SELECT COALESCE(SUM(amt), 0) FROM v WHERE city = 'Goa' return?

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

Correct answer: D. NULL and 0

SUM ignores NULLs, but when every input value is NULL (or there are no rows) it returns NULL, not 0. COALESCE converts that NULL to 0, which is what a report usually wants.

More Operations, Supply Chain & Business Analytics questions

Exams that ask this topic