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?
DELETE FROM Acct
WHERE bal < (SELECT AVG(bal) FROM Acct a2 WHERE a2.branch = Acct.branch);
SELECT COUNT(*) FROM Acct;
  1. A. 6
  2. B. 5
  3. C. 3
  4. D. 4

Correct answer: B. 5

Branch averages (NULL ignored): Agra 1000, Bhopal 700, Cuttack 2000. Only account 101 (500 < 1000) is deleted. The NULL-balance account is not deleted because NULL < 1000 is unknown. 5 rows remain.

More DBMS and SQL questions

Exams that ask this topic