CS FundamentalsHardProduct placement · SQL round

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 FROM Acct
GROUP BY branch
HAVING COUNT(DISTINCT bal) = COUNT(bal)
ORDER BY branch;
  1. A. Bhopal
  2. B. Cuttack
  3. C. Agra, Bhopal, Cuttack
  4. D. Agra, Cuttack

Correct answer: D. Agra, Cuttack

Bhopal has two equal balances (700, 700), so its distinct count 1 ≠ 2. Agra's non-NULL balances 500 and 1500 are distinct (the NULL is ignored by both counts), and Cuttack has one.

More DBMS and SQL questions

Exams that ask this topic