Uploaded by Đại Trần

Lab1 dbi

advertisement
Giving a database schema:
-
Sailors(sid: integer, sname: string, rating: integer, age:real)
-
Boats(bid:integer , bname: string, color: string)
-
Reserves(sid: integer, bid: integer , day: date )
Sid
22
29
31
32
58
64
71
74
85
95
Sname
Dustin
Brutus
Lubber
Andy
Rusty
Horatio
Zorba
Horatio
Art
Bob
Rating
7
1
8
8
10
7
10
9
3
3
Age
45.0
33.0
55.5
25.5
35.0
35.0
16.0
35.0
25.5
63.5
Sid
22
22
22
22
31
31
31
64
64
74
Bid
101
102
103
104
102
103
104
101
102
103
Day
10/10/08
10/10/08
10/08/08
10/07/08
11/10/08
11/06/08
11/12/08
9/05/08
9/08/08
9/08/08
Bid
101
102
103
104
Bname
Interlake
Interlake
Clipper
Marine
Color
Blue
Red
Green
Red
Boats
Sailors
Reserves
Using relational algebra expression to answer below queries
1.
Find the names of sailors who have reserved boat 104
π Sname(σ Bid=104 (Sailor ⋈<S.Sid = R.Sid> R))
2.
Find the names of sailors who have reserved a blue boat
π Sname(σColor=Blue ( S ⋈ (B ⋈R)))
3.
Find the colors of boats reserved by Bob.
π Color(σS.name=Bob ( S ⋈ (B ⋈ R)))
4.
Find the names of sailors who is older than 25 have reserved at least one boat.
π Sname(σ Age > 25 ( S ⋈<S.Sid = R.Sid> R))
5.
Find the names of sailors who have reserved a red or a blue boat
πSname (σColor=Red or Color=Blue( S ⋈ (B ⋈ R)))
6.
Find the names of sailors who have reserved a red boat name Marine but not Red boat
call Interlake
πSname ((σColor = Red AND Sname = Marine ( S ⋈ (B ⋈ R))) - πSname ((σColor = Red AND (Bid =
101 OR BID = 102) ( S ⋈ (B ⋈ R)))
7.
Find the sids of sailors with age over 20 who have not reserved a Green boat
πSid(σAge > 20 (S)) - πSid(σColor = Green (B⋈R))
7.
Find the names of sailors who have reserved boat in the period from 15th to the end of
that month
π Sname(σ Day >= DATE(15/MM/YY) S ⨝ <S.Sid = R.Sid> R)
8.
Find the names of sailors who have reserved all boats called Interlake
π Sname(σ Bid=101 or Bid = 102 (Sailor ⋈<S.Sid = R.Sid> Reserves))
9.
Find the names of sailors who have reserved at least two boats
πsname (σ count Sid >=2(Sailors ⨝ <S.Sid = R.Sid> Reserves))
Download