CS FundamentalsVery hardGATE CS
T(g, v) = (g1, 5), (g1, 15), (g2, 8), (g2, 9), (g2, NULL), (g3, 50), (g4, NULL), (g4, NULL), (g5, 12), (g5, 3). How many groups does SELECT g FROM T GROUP BY g HAVING SUM(CASE WHEN v > 10 THEN 1 END) IS NULL OR MAX(v) > 40 return?
- A. 1
- B. 3
- C. 4
- D. 2
Correct answer: B. 3
CASE without ELSE yields NULL when the condition is false or UNKNOWN, so SUM over a group where no row exceeds 10 (or all v are NULL) is NULL. That holds for g2 and g4, and g3 passes by MAX(v) > 40: 3 groups. Adding ELSE 0 would make the sums 0 instead of NULL and give 1.
More DBMS and SQL questions
- Tk(s, c) = (s1, c1), (s1, c2), (s1, c3), (s2, c1), (s2, c2), (s3, c1), (s3, c2), (s3, c3), (s3, c4), (s4, c3), (s5, c2), (s5, c3), (s5…
- M(s) holds the scores 90, 85, 85, 80, 80, 80, 70, 70, 60. What is the sum over all nine rows of (RANK() OVER (ORDER BY s DESC)…
- A(x) = (3, 5, NULL, 8, 9, 12) and B(x) = (4, NULL, 6). How many rows does SELECT x FROM A WHERE x > ALL (SELECT x FROM B) return? (ALL is…
- R(A, B) has 5000 tuples with V(R, B) = 100 distinct B values. S(B, C) has 3000 tuples with V(S, B) = 300 and V(S, C) = 60. Using the…
- R(A, B, C, D, E, F, G) has the functional dependencies AB -> C, C -> D, D -> E, E -> C, F -> G, BG -> A and AE -> F. How many candidate…
- R(A, B, C, D, E) has the functional dependencies A -> B, BC -> D, D -> E and E -> B. The decomposition R1(A, B), R2(B, C, D), R3(A, D, E) is