Uploaded by Xuân Lộc Lương

1715753021425 645842d96e8314d66777cbcc Lab1

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
Boats
Sailors
Reserves
Using relational algebra expression to answer below queries
1. Find the names of sailors who have reserved boat 104
𝜋𝑆𝑎𝑖𝑙𝑜𝑟𝑠.𝑆𝑛𝑎𝑚𝑒 (𝜎𝑅𝑒𝑠𝑒𝑟𝑣𝑒𝑠.𝑏𝑖𝑑=104 𝑆𝑎𝑖𝑙𝑜𝑟𝑠⨝Reserves)
2. Find the names of sailors who have reserved a blue boat
𝜋𝑆𝑎𝑖𝑙𝑜𝑟𝑠.𝑆𝑛𝑎𝑚𝑒 ((𝜎𝐵𝑜𝑎𝑡𝑠.𝐶𝑜𝑙𝑜𝑟=′𝐵𝑙𝑢𝑒′ 𝑅𝑒𝑠𝑒𝑟𝑣𝑒𝑠⨝Boats) ⨝Sailors)
3. Find the colors of boats reserved by Bob.
𝜋𝐵𝑜𝑎𝑡𝑠.𝑐𝑜𝑙𝑜𝑟 ((𝜎𝑆𝑎𝑖𝑙𝑜𝑟𝑠.𝑆𝑛𝑎𝑚𝑒=′𝐵𝑜𝑏′ 𝑆𝑎𝑖𝑙𝑜𝑟𝑠⨝Reserves) ⨝Boats)
4. Find the names of sailors who is older than 25 have reserved at least one boat.
𝜋𝑆𝑎𝑖𝑙𝑜𝑟𝑠.𝑆𝑛𝑎𝑚𝑒 (𝜎𝐶𝑂𝑈𝑁𝑇(𝑅𝑒𝑠𝑒𝑟𝑣𝑒𝑠.𝐵𝑖𝑑)≥1 𝐴𝑁𝐷 𝑆𝑎𝑖𝑙𝑜𝑟𝑠.𝐴𝑔𝑒>25 𝑅𝑒𝑠𝑒𝑟𝑣𝑒𝑠 ⟖Sailors)
5. Find the names of sailors who have reserved a red or a blue boat
𝜋𝑆𝑎𝑖𝑙𝑜𝑟𝑠.𝑆𝑛𝑎𝑚𝑒 (𝜎𝐵𝑜𝑎𝑡𝑠.𝐶𝑜𝑙𝑜𝑟=′ 𝑅𝑒𝑑′ 𝑂𝑅 𝐵𝑜𝑎𝑡𝑠.𝐶𝑜𝑙𝑜𝑟=′𝐵𝑙𝑢𝑒′ 𝐵𝑜𝑎𝑡𝑠⨝ Reserves) ⨝Sailors)
6. Find the names of sailors who have reserved a red boat name Marine but not Red boat call
Interlake
𝜋𝑆𝑎𝑖𝑙𝑜𝑟𝑠.𝑆𝑛𝑎𝑚𝑒 (𝜎𝐵𝑜𝑎𝑡𝑠.𝐶𝑜𝑙𝑜𝑟=′ 𝑅𝑒𝑑′ 𝐴𝑁𝐷 𝐵𝑜𝑎𝑡𝑠.𝐵𝑛𝑎𝑚𝑒=′𝑀𝑎𝑟𝑖𝑛𝑒′ 𝐵𝑜𝑎𝑡𝑠⨝Reserves)⨝Sailors)
7. Find the sids of sailors with age over 20 who have not reserved a Green boat
𝜋𝑆𝑎𝑖𝑙𝑜𝑟𝑠.𝑆𝑖𝑑 ((𝜎𝑁𝑂𝑇 𝐵𝑜𝑎𝑡𝑠.𝑐𝑜𝑙𝑜𝑟=′ 𝐺𝑟𝑒𝑒𝑛′ 𝐴𝑁𝐷 𝑆𝑎𝑖𝑙𝑜𝑟𝑠.𝐴𝑔𝑒>20 𝐵𝑜𝑎𝑡𝑠⨝Reserves)⨝Sailors)
Color
Blue
Red
Green
Red
8. Find the names of sailors who have reserved boat in the period from 15th to the end of that
month
𝜋𝑆𝑎𝑖𝑙𝑜𝑟𝑠.𝑆𝑛𝑎𝑚𝑒 ((𝜎𝐷𝐴𝑌(𝑅𝑒𝑠𝑒𝑟𝑣𝑒𝑠.𝐷𝑎𝑦)≥15 𝐵𝑜𝑎𝑡𝑠⨝Reserves)⨝Sailors)
9. Find the names of sailors who have reserved all boats called Interlake
𝜋𝑆𝑎𝑖𝑙𝑜𝑟𝑠.𝑆𝑛𝑎𝑚𝑒 ((𝜎𝐵𝑜𝑎𝑡𝑠.𝐵𝑛𝑎𝑚𝑒=′𝐼𝑛𝑡𝑒𝑟𝑙𝑎𝑘𝑒′ 𝐵𝑜𝑎𝑡𝑠⨝Reserves)⨝Sailors)
10. Find the names of sailors who have reserved at least two boats
𝜋𝑆𝑎𝑖𝑙𝑜𝑟𝑠.𝑆𝑛𝑎𝑚𝑒 ((𝜎𝐶𝑂𝑈𝑁𝑇(𝑅𝑒𝑠𝑒𝑟𝑣𝑒𝑠.𝐵𝑖𝑑)≥2 Sailors⨝Reserves)
Download