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;
- A. 6800
- B. 6300
- C. 5900
- 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
- Which statement about snapshot isolation (SI) is correct?
- R(A, B) has 300 tuples and S(B, C) has 50 tuples, where S.B is the primary key of S and R.B is a foreign key referencing it (NOT NULL)…
- Table P(x) rows: (1), (2), (2), (3), (NULL). Table Q(x) rows: (2), (3), (3), (NULL), (4). What does this query return? sql SELECT COUNT()…
- R has 500 tuples in 50 blocks and S has 4000 tuples in 200 blocks. With only enough memory for one block of each relation, how many block…
- Under BOTH wait-die and wound-wait deadlock prevention, which transaction can be rolled back when a lock conflict occurs?
- Table Acct(no, branch, bal) rows: (101, 'Agra', 500), (102, 'Agra', 1500), (103, 'Bhopal', 700), (104, 'Bhopal', 700), (105, 'Cuttack'…