CS FundamentalsHardAmazon/Flipkart SQL round · GATE CS

Table Takes(sid, cid, marks) rows: (1, 'C1', 80), (1, 'C2', NULL), (2, 'C1', 65), (3, 'C2', 90), (3, 'C3', 75), (5, 'C1', 50). What does this query return?

Table Takes(sid, cid, marks) rows: (1, 'C1', 80), (1, 'C2', NULL), (2, 'C1', 65), (3, 'C2', 90), (3, 'C3', 75), (5, 'C1', 50). What does this query return?
SELECT cid, AVG(marks), COUNT(*)
FROM Takes
GROUP BY cid
ORDER BY cid;
  1. A. (C1, 65, 3), (C2, 45, 2), (C3, 75, 1)
  2. B. (C1, 72.5, 2), (C2, 90, 2), (C3, 75, 1)
  3. C. (C1, 65, 3), (C2, 90, 1), (C3, 75, 1)
  4. D. (C1, 65, 3), (C2, 90, 2), (C3, 75, 1)

Correct answer: D. (C1, 65, 3), (C2, 90, 2), (C3, 75, 1)

C1: (80 + 65 + 50)/3 = 65 (sid 5 counts, Takes has no FK check here). C2: AVG skips the NULL so it is 90, while COUNT(*) still counts 2 rows.

More DBMS and SQL questions

Exams that ask this topic