CS FundamentalsVery hardProduct-company placement · GATE CS

Fee(sid, fee) has rows (1, 500), (2, 700), (3, 700), (4, 400), (5, 900), (6, 400). What does this return? SELECT SUM(fee) FROM Fee f WHERE 3 > (SELECT COUNT(DISTINCT fee) FROM Fee f2 WHERE f2.fee > f.fee);

  1. A. 2300
  2. B. 2100
  3. C. 2800
  4. D. 3600

Correct answer: C. 2800

A row qualifies if fewer than 3 distinct fees are higher: 900 (0 higher), both 700s (1) and 500 (2) qualify, the 400s (3) do not. Sum = 900 + 700 + 700 + 500 = 2800. 2300 is what COUNT(*) instead of COUNT(DISTINCT) gives, and 2100 adds each distinct value once.

More DBMS and SQL questions

Exams that ask this topic