CS FundamentalsHardProduct placement · SQL round

Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4, 'Dev', 'Tech', NULL, 3), (5, 'Esha', NULL, 35, 3), (6, 'Farid', 'Tech', 70, 2). What counts do Query 1 and Query 2 return?

Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4, 'Dev', 'Tech', NULL, 3), (5, 'Esha', NULL, 35, 3), (6, 'Farid', 'Tech', 70, 2). What counts do Query 1 and Query 2 return?
-- Query 1
SELECT COUNT(*) FROM (SELECT COUNT(*), SUM(pay) FROM Staff WHERE pay > 100);
-- Query 2
SELECT COUNT(*) FROM (SELECT dept, COUNT(*) FROM Staff WHERE pay > 100 GROUP BY dept);
  1. A. 0 and 1
  2. B. 0 and 0
  3. C. 1 and 1
  4. D. 1 and 0

Correct answer: D. 1 and 0

An aggregate without GROUP BY always returns exactly one row (COUNT 0, SUM NULL) even when no row qualifies. With GROUP BY there are no groups, so no rows.

More DBMS and SQL questions

Exams that ask this topic