4. a) Suppose relation R(a,b.c) has the following tuples: (1,1.3), (1,2,3), (2,1
ID: 3905803 • Letter: 4
Question
4. a) Suppose relation R(a,b.c) has the following tuples: (1,1.3), (1,2,3), (2,1,4), (2,3,5), (2,4,1), (3,2,4), and (3,3,6). Define the view Vby: CREATE VIEW V AS SELECT a+b AS d, c FROM R; What is the result of the query: SELECT d, SUM(c) FROM V GROUP BY d HAVING COUNT1; (5) b) The table Arc(x.y) currently has the following tuples (note there are duplicates): (1,2), (1,2), (2,3), (3,4), (3,4), (4,1), (4,1), (4,1), (4,2). Compute the result of the query: SELECT al.x, a2.y, COUNT(*) FROM Arc a1, Arc a2 WHERE al.y = a2.x GROUP BY al.x, a2.y;Explanation / Answer
If you have any doutbs, please give me comment...
R(a, b, c)
1 1 3
1 2 3
2 1 4
2 3 5
2 4 1
3 2 4
3 3 6
V(d,c)
2 3
3 3
3 4
5 5
6 1
5 4
6 6
GROUP BY d
d -> count(*)
2 -> 1
3 -> 2
5 -> 2
6 -> 2
result:
3 7
5 9
6 7
2)
Arc(x,y)
1 2
1 2
2 3
3 4
4 1
4 1
4 1
4 2
SELECT * FROM Arc1 a1, Arc a2 WHERE a1.y = a2.x;
1 2 2 3
1 2 2 3
2 3 3 4
3 4 4 1
3 4 4 1
3 4 4 1
3 4 4 2
4 1 1 2
4 1 1 2
4 1 1 2
4 1 1 2
4 1 1 2
4 1 1 2
4 2 2 3
GROUP BY a1.x, a2.y
1 2 2 3
2 3 3 4
3 4 4 1
3 4 4 2
4 1 1 2
4 2 2 3
result:
1 3 2
2 4 1
3 1 3
3 2 1
4 2 6
4 3 1
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.