CS FundamentalsVery hardGATE CS · SQL

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 COUNT(*) FROM Acct a
WHERE 1 >= (SELECT COUNT(*) FROM Acct b WHERE b.bal > a.bal);
  1. A. 4
  2. B. 1
  3. C. 3
  4. D. 2

Correct answer: C. 3

2000 has no larger balance and 1500 has one, so both qualify; each 700 has two larger. The trap is account 106: b.bal > NULL is never TRUE, so its inner COUNT is 0 and it qualifies too, giving 3, not 2.

More DBMS and SQL questions

Exams that ask this topic