CS FundamentalsHardAmazon/Flipkart SQL round · GATE CS

Table Acct(no, branch, bal) rows: (101, 'Agra', 500), (102, 'Agra', 1500), (103, 'Bhopal', 700), (104, 'Bhopal', 700), (105, 'Cuttack', 2000), (106, 'Agra', NULL). What does this query return?

Table Acct(no, branch, bal) rows: (101, 'Agra', 500), (102, 'Agra', 1500), (103, 'Bhopal', 700), (104, 'Bhopal', 700), (105, 'Cuttack', 2000), (106, 'Agra', NULL). What does this query return?
UPDATE Acct
SET bal = CASE WHEN bal < 1000 THEN bal * 2 ELSE bal - 500 END;
SELECT SUM(bal) FROM Acct;
  1. A. 6800
  2. B. 6300
  3. C. 5900
  4. D. NULL

Correct answer: B. 6300

500 → 1000, 1500 → 1000, 700 → 1400 twice, 2000 → 1500; the NULL balance fails the WHEN test, goes to ELSE and NULL − 500 stays NULL, which SUM ignores: 6300.

More DBMS and SQL questions

Exams that ask this topic