-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathq6.sql
More file actions
33 lines (27 loc) · 648 Bytes
/
q6.sql
File metadata and controls
33 lines (27 loc) · 648 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
-- (Q6) Find the names of sailors who have reserved a red and a green boat.
/* relational algebra
sigma :: selection
pi :: projection
x :: natural join
p :: renaming
U :: union
p(Tempred, pi_sid(sigma_{color = 'red'}Boats x Reserves))
p(Tempgreen, pi_sid(sigma_{color = 'green'}Boats x Reserves))
pi_sname((Tempred U Tempgreen) x Sailors)
*/
use dbms_exercises;
SELECT S.sname
FROM Sailors S, Reserves R1, Boats B1, Reserves R2, Boats B2
WHERE S.sid = R1.sid
AND R1.bid = B1.bid
AND S.sid = R2.sid
AND R2.bid = B2.bid
AND B1.color= 'red'
AND B2.color = 'green'
/* result
sname
Dustin
Dustin
Lubber
Lubber
*/