CS FundamentalsModerateGATE CS (PYQ pattern)
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 MT b WHERE b.g = a.g) return?
- A. 130
- B. 180
- C. 170
- D. 230
Correct answer: C. 170
Averages: g1 = 15, g2 = 40, g3 = 60. Rows with v >= their group average: 20 (g1), 40 and 50 (g2), 60 (g3; equal to its average counts because of >=). Sum = 170.
More DBMS and SQL questions
- 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?
- A table is stored sorted on key K in 5000 pages (100 records each). Searching for one key with binary search over pages costs ceil(log2…