CS FundamentalsEasyGATE CS (PYQ pattern)
CO(c, n): (a,1), (a,2), (b,3), (b,3), (c,NULL), (c,4). What are COUNT(DISTINCT n), SUM(n), SUM(DISTINCT n) and AVG(n), in that order?
- A. 5, 13, 10, 2.6
- B. 4, 13, 10, 2.6
- C. 4, 16, 10, 2.16667
- D. 4, 13, 13, 2.5
Correct answer: B. 4, 13, 10, 2.6
Distinct non-NULL n values are 1, 2, 3, 4 (4 of them, SUM(DISTINCT) = 10). SUM(n) = 13 (3 counted twice, NULL skipped). AVG skips NULL: 13 / 5 = 2.6, not 13 / 6.
More DBMS and SQL questions
- MT(id, g, v): (1,1,10), (2,1,20), (3,2,30), (4,2,40), (5,2,50), (6,3,60). What does SELECT SUM(v) FROM MT a WHERE v >= (SELECT AVG(v) FROM…
- VW(id, v): (1,5), (2,15), (3,25) and the view BIG = SELECT id, v FROM VW WHERE v > 10. Two more rows (4,8) and (5,30) are then inserted…
- Relation R(A, B) has 6 tuples with 4 distinct values of A and 5 distinct values of B. What are the minimum and maximum possible…
- Relations R and S have 40 and 60 tuples (union-compatible). What are the minimum and maximum cardinalities of R ∪ S, R ∩ S and R − S (in…
- R(A, B) has 1000 tuples; S(B, C) has 500 tuples with B a key of S; T(C, D) has 200 tuples with C a key of T, and S.C is a NOT NULL foreign…
- The tuple calculus expression { t | ¬ Student(t) } over a database with a Student relation: is it safe, and why?