CS FundamentalsHardGATE CS (PYQ pattern)
Table AA(x, y): (1,1), (1,2), (2,2), (2,NULL), (3,NULL), (NULL,3). How many groups does SELECT x FROM AA GROUP BY x HAVING COUNT(y) < COUNT(*) return?
- A. 1
- B. 3
- C. 4
- D. 2
Correct answer: D. 2
COUNT(y) < COUNT(*) means the group contains a NULL y: x = 2 (one NULL) and x = 3 (all NULL). x = 1 has none and the NULL-x group has y = 3 only. So 2 groups.
More DBMS and SQL questions
- QA(a, b): (1,2), (2,3), (3,1), (4,4). How many rows does SELECT FROM QA x JOIN QA y ON x.b = y.a JOIN QA z ON y.b = z.a return?
- 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?
- 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…