CS FundamentalsEasyGATE CS (PYQ pattern)

Table N(id) has 10 rows with ids 1 to 10. For SELECT id, NTILE(4) OVER (ORDER BY id) AS g, CUME_DIST() OVER (ORDER BY id) AS cd FROM N, which ids get g = 2, and what is cd for id = 5?

  1. A. ids 4, 5, 6; cd = 0.5
  2. B. ids 3, 4, 5; cd = 0.5
  3. C. ids 4, 5, 6; cd = 0.4
  4. D. ids 4, 5; cd = 0.5

Correct answer: A. ids 4, 5, 6; cd = 0.5

NTILE(4) over 10 rows makes buckets of 3, 3, 2, 2 (the first 10 mod 4 = 2 buckets get the extra row): ids 1-3, 4-6, 7-8, 9-10. CUME_DIST = rows with id <= 5 divided by 10 = 0.5; 0.4 counts only the rows strictly before id 5.

More DBMS and SQL questions

Exams that ask this topic