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?
- A. ids 4, 5, 6; cd = 0.5
- B. ids 3, 4, 5; cd = 0.5
- C. ids 4, 5, 6; cd = 0.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
- Table K(a, b): (0,5), (3,7), (0,NULL), (NULL,4), (2,NULL), (0,0). What does SELECT SUM(COALESCE(NULLIF(a, 0), b)) FROM K return?
- ORD(oid, amt): (1,100), (2,200), (3,300). LN(oid, item): (1,a), (1,b), (1,c), (2,a), (3,b), (3,c). PAY(oid, paid): (1,40), (1,60)…
- EM(id, sal, mgr): (1,90,NULL), (2,70,1), (3,70,1), (4,95,2), (5,60,2), (6,40,3), (7,80,3), (8,NULL,4), (9,85,7). How many rows does SELECT…
- Table UP(a, b): (1,10), (2,20), (3,30). After UPDATE UP SET a = b, b = a; (standard SQL semantics), what is the sum of column a and the…
- Table DU(a, b): (1,NULL), (1,NULL), (2,3), (2,3), (NULL,5), (NULL,5), (1,2). Let x = rows returned by SELECT DISTINCT a, b FROM DU, y =…
- R(A, B) and S(B) are relations. Which relational-algebra expression computes the division R ÷ S (the A-values that are paired in R with…