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'?
- A. 120 and NULL
- B. Both return 120
- C. 120 and 0
- 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.
Practise more Operations, Supply Chain & Business Analytics questionsOperations, Supply Chain & Business Analytics: notes and key points
More Operations, Supply Chain & Business Analytics questions
- Daily demand is a steady 50 units, the order quantity is 200 units, and the supplier's lead time is 10 days. At what on-hand stock level…
- Lead-time demand is normal with a standard deviation of 40 units, and the firm holds 60 units of safety stock. What cycle-service level…
- Product X (lead time 1 week) needs 2 units of Y; Y (lead time 2 weeks) needs 3 units of Z; Z has a lead time of 1 week. 100 units of X are…
- Four jobs wait at one machine (processing hours; weight = importance): A (4; 1), B (2; 3), C (6; 2), D (3; 3). Using the weighted shortest…
- Seven jobs taking 8, 7, 6, 5, 4, 3 and 2 hours are to be run on three identical parallel machines. Using the longest-processing-time (LPT)…
- A machine has a mean time between failures of 400 hours and a mean time to repair of 20 hours. What is its steady-state availability?