Presentation is loading. Please wait.

Presentation is loading. Please wait.

SQL Exercises. 1) Names of suppliers. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

Similar presentations


Presentation on theme: "SQL Exercises. 1) Names of suppliers. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)"— Presentation transcript:

1 SQL Exercises

2 1) Names of suppliers. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

3 2) Names of suppliers who supply some part. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

4 3) Names of suppliers who supply some red part. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

5 4) Names of suppliers who supply some red part and are at 221 Packer Street. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

6 5) Names of suppliers who supply some red part or are at 221 Packer Street. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

7 6) Pairs of sids (sid1, sid2) such that the sid1 is more expensive for some part than sid2 Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

8 7) Pids of the most expensive parts supplied by supplier s177. 3 versions! (using ALL, NOT EXISTS, EXCEPT) Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

9 8) Pids of parts supplied which are only supplied at less than $200. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

10 9) Sids of suppliers who supply every red part. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

11 10) Sids of suppliers who supply every part that is either red or green part. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

12 11) Sids of suppliers who supply every red part or every green part. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

13 12) Find the average price of red parts Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

14 13) For each color, find the number of parts with that color. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

15 14) For each color, find the number of parts with that color, provided that the average cost (of parts with that color) is at least 40. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

16 15) Find the number of parts that are not supplied by any supplier Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

17 16) Find the total number of tuples in all three tables. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

18 17) Find the average number of tuples per table in the three database tables Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

19 18) Find names of suppliers who supply at least 6 different parts Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

20 19) Find all suppliers who supply a part with an unknown (i.e., null) color. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

21 20) For each supplier, return the number of parts supplied by that supplier, which have an unknown (i.e., null) color. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

22 21) Find the names of all parts whose color starts with the letter b. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

23 22) For each part in Catalog, return its pid, along with the cheapest price and the most expensive price, for which it is supplied. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

24 23) For each part in Part, return pid, along with the cheapest price and the most expensive price, for which it is supplied. If the part is not supplied, then the cheapest and most expensive prices should be null. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)


Download ppt "SQL Exercises. 1) Names of suppliers. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)"

Similar presentations


Ads by Google