CS FundamentalsHardTCS 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 COUNT(DISTINCT bal), COUNT(bal), SUM(DISTINCT bal)
FROM Acct;
  1. A. 4, 5, 4700
  2. B. 4, 5, 5400
  3. C. 4, 6, 4700
  4. D. 5, 5, 5400

Correct answer: A. 4, 5, 4700

Non-NULL balances: 500, 1500, 700, 700, 2000. COUNT(bal) = 5; DISTINCT values are 500, 700, 1500, 2000 (4) summing to 4700; the plain sum would be 5400.

More DBMS and SQL questions

Exams that ask this topic