Lab1 Bikip

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

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 Sname Ratin Age Sid Bid Day Bid Bname Color
g 22 101 10/10/08 101 Interlake Blue
22 Dustin 7 45.0 22 102 10/10/08 102 Interlake Red
29 Brutus 1 33.0 22 103 10/08/08 103 Clipper Green
31 Lubber 8 55.5 22 104 10/07/08 104 Marine Red
32 Andy 8 25.5 31 102 11/10/08
58 Rusty 10 35.0 Boats
31 103 11/06/08
64 Horatio 7 35.0 31 104 11/12/08
71 Zorba 10 16.0 64 101 9/05/08
74 Horatio 9 35.0 64 102 9/08/08
85 Art 3 25.5 74 103 9/08/08
95 Bob 3 63.5
Sailors Reserves

Using relational algebra expression to answer below queries

1. Find the names of sailors who have reserved boat 103

Sid Sname Ratin Age


g
22 Dustin 7 45.0
31 Lubber 8 55.5
74 Horatio 9 35.0

πSailors.Sname(σSailors.Sid=Reserves.Sid AND(Reserves.Bid= “103”))

2. Find the names of sailors who have reserved a red boat

Sid Sname Ratin Age


g
22 Dustin 7 45.0
31 Lubber 8 55.5
64 Horatio 7 35.0

πSailors.Sname(σBoats.color= “Red” AND (Boats.Bid=Reserves.Bid ) AND (Reserves.Sid=Sailors.Sid)

3. Find the colors of boats reserved by Lubber.

Bid Bname Color


102 Interlake Red
103 Clipper Green
πBoats.Color(σSailors.Sname=“Lubber” AND (Sailors.Sid=Reserves.Sid )AND(Reserves.Bid=Boats.Bid))

4. Find the names of sailors who have reserved at least one boat.

Sid Sname Ratin Age


g
74 Horatio 9 35.0

πSailors.Sname(σSailors.Sid=Reserves.Sid)

5. Find the names of sailors who have reserved a red or a green boat

Sid Sname Ratin Age


g
22 Dustin 7 45.0
31 Lubber 8 55.5
64 Horatio 7 35.0
74 Horatio 9 35.0

πSailors.Sname(σBoats.Color=“Red”OR Boats.Color=“Green”AND(Boats.Bid=Reserves.Bid)AND(Reserves.Sid=Sailors.Sid))
6. Find the names of sailors who have reserved a red and a green boat

Sid Sname Ratin Age


g
22 Dustin 7 45.0
31 Lubber 8 55.5
πSailors.Sname(σBoats.Color= “Red”AND Boats.Color= “Green”AND(Boats.Bid=Reserves.Bid)AND(Reserves.Sid=Sailors.Sid))

7. Find the sids of sailors with age over 20 who have not reserved a red boat

Sid Sname Ratin Age


g
29 Brutus 1 33.0
32 Andy 8 25.5
58 Rusty 10 35.0
74 Horatio 9 35.0
85 Art 3 25.5
95 Bob 3 63.5

πSailors.Sid(σSailors.Age>20 AND (Boats.Color! = “Red”) AND (Boats.Bid=Reserves.Bid) AND (Reserves.Sid=Sailors.Sid))


8. Find the names of sailors who have reserved all boats
Sid Sname Ratin Age
g
22 Dustin 7 45.0

πSailors.Sname(σCOUNT(DISTINCT Reserves.Bid)=COUNT(DISTINCT Boats.Bid)AND(Boats.Bid=Reserves.Bid) AND (Reserves.Sid=Sailors.Sid))

9. Find the names of sailors who have reserved all boats called Interlake

Sid Sname Ratin Age


g
22 Dustin 7 45.0
64 Horatio 7 35.0

πSailors.Sname(σCOUNT (DISTINCTReserves.Bid) = COUNT(DISTINCT Boats.Bid) AND (Boats.Bname=Reserves.)AND (Reserves.Sid=Sailors.Sid))

10. Find the names of sailors who have reserved at least two boats

πSailors.Sname(σCOUNT (DISTINCTReserves.Bid) >=2 AND (Boats.Bid=Reserves.Bid)AND (Reserves.Sid=Sailors.Sid))

You might also like