Question

In: Computer Science

Consider the following schema: Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost) In a plain...

Consider the following schema:

Suppliers(sid, sname, address)
Parts(
pid, pname, color)
Catalog(sid,
pid, cost)

In a plain text file, write the following queries in SQL:

  1. Find the names of all suppliers who supply a green part.
  2. Find the names of all suppliers who are from Illinois.
  3. Find the names of all suppliers who sell a red part costing less than $100.
  4. Find the names and colors of all parts that are green or red.

In writing these queries you may make the following assumptions:

a. Each part has only one color.
b. The cost field is a real number with two decimal places (e.g., 100.25, 93.00).
c. The sid field in Suppliers and the sid field in Catalog refer to the same field.
d. The pid field in Parts and the pid field in Catalog refer to the same field.

Solutions

Expert Solution

Answer:

Find the names of all suppliers who supply a green part.

Select s.sname,p.color from Suppliers s
join Catalog c on c.sid=s.sid
join Parts p on p.pid = c.pid
where p.Color = "Green" order by s.sname;

/*The above query will return the names of suppliers who supply green part*/

Find the names of all suppliers who are from Illinois.

Select * from Suppliers where address like '%illinois%'
/*The above query will return names of all suppliers who are from Illinois*/

Find the names of all suppliers who sell a red part costing less than $100.

Select s.sname,p.color from Suppliers s
join Catalog c on c.sid=s.sid
join Parts p on p.pid = c.pid
where p.Color = "red" c.cost < 100.00 order by s.sname;

/*The above query will return the names of all suppliers who sell a red part costing less than $100*/

Find the names and colors of all parts that are green or red.

Select pname,color from Parts where color in ('green','red');
/*The above query will return the names and colors of all parts that are green or red*/

Thanks and all the best. Let me know in case if you have any doubts.


Related Solutions

Consider the following schema: Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost) In a plain...
Consider the following schema: Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost) In a plain text file, write the following queries in SQL: 1.Find the names of all suppliers who supply a green part. 2.Find the names of all suppliers who are from Illinois. 3.Find the names of all suppliers who sell a red part costing less than $100. 4.Find the names and colors of all parts that are green or red. In writing these (basic) queries you may...
Consider the following schema: Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost) write the following...
Consider the following schema: Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost) write the following queries in SQL: * Find the names of all suppliers who supply a green part. *Find the names of all suppliers who are from Illinois. *Find the names of all suppliers who sell a red part costing less than $100. *Find the names and colors of all parts that are green or red. In writing these queries you may make the following assumptions: a....
Consider the following schema: Suppliers (sid, sname, address) Parts (pid, pname, colour) Catalog(sid, pid, cost) The key for Suppliers is sid, for Parts is pid, and for Catalog is sid and pid The Ca...
Consider the following schema: Suppliers (sid, sname, address) Parts (pid, pname, colour) Catalog(sid, pid, cost) The key for Suppliers is sid, for Parts is pid, and for Catalog is sid and pid The Catalog relation associates prices charged for parts by suppliers. Write the following queries using relational algebra. For items (a) through (e), use the "sequences of assignments" form. For items (f) and (g), use the "expression tree" form. List all assumptions. (Some marks will be given for the quality of your answers.) (a) Find...
INRO TO DATABASES Consider the following Schema: Suppliers(sid: integer, sname: string, address: string) Parts(pid: integer, pname:...
INRO TO DATABASES Consider the following Schema: Suppliers(sid: integer, sname: string, address: string) Parts(pid: integer, pname: string, color: string) Catalog(sid: integer, pid: integer, cost: real) The Catalog relation lists the prices charged for parts by Suppliers. Write the following queries in SQL using join, nested queries and set operators. 1. Find names of suppliers who supply every red or green part. 2. Find the sids of suppliers who supply every red part or supply every green part. 3. Find sids...
Consider the University Database with the following relations: Professors (pid, pname, dept, ext) Students (sid, sname,...
Consider the University Database with the following relations: Professors (pid, pname, dept, ext) Students (sid, sname, major-dept, year) Courses (cid, cname, dept, credithours) Enrollment (sem-year, sid, cid, grade) Teaches (pid, cid, sem-year, class-size) where, Professors: All professors have professor id (pid), name (pname), department that they work (dept), and a phone number extension for their office (ext). Students: All students have id (sid), name (sname), department for their major (major-dept), and a year (year i.e, freshman, sophomore, junior, etc). Courses:...
Consider the University Database with the following relations: Professors (pid, pname, dept, ext) Students (sid, sname,...
Consider the University Database with the following relations: Professors (pid, pname, dept, ext) Students (sid, sname, major-dept, year) Courses (cid, cname, dept, credithours)Enrollment (sem-year, sid, cid, grade) Teaches (pid, cid, sem-year, class-size), Professors: All professors have professor id (pid), name (pname), department that they work (dept), and a phone number extension for their office (ext). Students: All students have id (sid), name (sname), department for their major (major-dept), and a year (yeari.e, freshman, sophomore, junior, etc). Courses: All courses have...
Consider the University Database with the following relations: Professors (pid, pname, dept, ext) Students (sid, sname,...
Consider the University Database with the following relations: Professors (pid, pname, dept, ext) Students (sid, sname, major-dept, year) Courses (cid, cname, dept, credithours) Enrollment (sem-year, sid, cid, grade) Teaches (pid, cid, sem-year, class-size) where, Professors: All professors have professor id (pid), name (pname), department that they work (dept), and a phone number extension for their office (ext). Students: All students have id (sid), name (sname), department for their major (major-dept), and a year (year i.e, freshman, sophomore, junior, etc). Courses:...
INTRO TO DATABASES Consider the boat reservation system: Sailors (sid, sname,rating, age) Boats(bid, bname, color) Reserves...
INTRO TO DATABASES Consider the boat reservation system: Sailors (sid, sname,rating, age) Boats(bid, bname, color) Reserves (sid, bid, day) Formulate the following question in relational algebra using two different sequences of relational operators: A. Find the colors of boats reserved by Lubber. B. Find the sids of sailors older than 20 who have not reserved a red boat.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT