CS FundamentalsModerateGATE CS (PYQ pattern)

GB(id, v): (1,5), (2,12), (3,18), (4,25), (5,31), (6,39), (7,NULL). The query SELECT v / 10, COUNT(*) FROM GB GROUP BY v / 10 uses integer division. How many groups (rows) does it return, and how many of them have COUNT(*) >= 2?

  1. A. 4 groups, 2 with at least 2 rows
  2. B. 5 groups, 2 with at least 2 rows
  3. C. 5 groups, 3 with at least 2 rows
  4. D. 6 groups, 1 with at least 2 rows

Correct answer: B. 5 groups, 2 with at least 2 rows

v / 10 gives 0 (v = 5), 1 (12, 18), 2 (25), 3 (31, 39) and NULL (the NULL row forms its own group). That is 5 groups; groups 1 and 3 have two rows each.

More DBMS and SQL questions

Exams that ask this topic