CS FundamentalsModerateTCS Digital · Infosys SP · 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?
SELECT branch, COUNT(*)
FROM Acct
GROUP BY branch
HAVING SUM(bal) >= 1400
ORDER BY branch;
  1. A. (Bhopal, 2), (Cuttack, 1)
  2. B. (Agra, 3), (Bhopal, 2), (Cuttack, 1)
  3. C. (Agra, 3), (Cuttack, 1)
  4. D. (Agra, 2), (Bhopal, 2), (Cuttack, 1)

Correct answer: B. (Agra, 3), (Bhopal, 2), (Cuttack, 1)

Agra's SUM ignores the NULL: 2000; Bhopal 1400 (≥ is inclusive); Cuttack 2000. COUNT(*) counts all of Agra's 3 rows, including the NULL balance.

More DBMS and SQL questions

Exams that ask this topic