Question

In: Computer Science

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 of suppliers who supply only red parts.

4. Find the pids of parts that are supplied by at least two different suppliers.

5. Find the sid of suppliers who charge more for some parts than the average price of that part.

Solutions

Expert Solution

Ans 1).

Select Suppliers.sid from Suppliers where not exists

(

(select Parts.pid from Parts where Parts.color=''red' or P.color=''green'')

except

(select Catalog.pid from Catalog where Catalog.sid=Suppliers.sid)

)

Ans 2).

(Select Suppliers.sid from Suppliers

where not exists

(

(select Parts.pid from Parts where Parts.color=''red')

except

(select Catalog.pid from Catalog where Catalog.sid=Suppliers.sid)

)

)

UNION

(select Suppliers.sid from Suppliers

where not exists

(

(select Parts.pid from Parts where Parts.color='green')

except

(select Catalog.pid from Catalog where Catalog.sid=Suppliers.sid)

)

)

Ans 3).

Select Suppliers.sid from Suppliers where not exists

(

(Select Parts.pid from Parts where Parts.color=''red')

except

(select Catalog.pid from Catalog where Catalog.sid=Suppliers.sid)

)

Ans 4).

select Catalog.pid from Catalog where exists

(

Select Catalog1.sid from Catalog1 where Catalog1.pid = Catalog.pid and Catalog1.sid != Catalog.sid

)

Ans 5).

Select sid, avg(cost) from Suppliers where cost>Avg(cost) group by pid;


Related Solutions

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...
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...
INTRO TO DATABASE Consider the Sailors-Boats-Reserves database described below. Sailors(sid: integer, sname: string, rating: integer, age:...
INTRO TO DATABASE Consider the Sailors-Boats-Reserves database described below. Sailors(sid: integer, sname: string, rating: integer, age: real) Boats(bid: integer, bname: string, color: string) Reserves(sid: integer, bid: integer, day: date) Write each of the following queries in SQL. 1. Find the names and ages of sailors who have reserved at least two boats. 2. For each boat reserved by at least 2 distinct sailors, find the boat id and the average age of sailors who reserved it.
Question (3) Consider the following relations: Student(snum: integer, sname: string, major: string, level: string, age: integer)...
Question (3) Consider the following relations: Student(snum: integer, sname: string, major: string, level: string, age: integer) Class(name: string, meets at: string, room: string, fid: integer) Enrolled(snum: integer, cname: string) Faculty(fid: integer, fname: string, deptid: integer) The meaning of these relations is straightforward; for example, Enrolled has one record per student-class pair such that the student is enrolled in the class. Write the following queries in Oracle SQL. No duplicates should be printed in any of the answers. i) (2 points)...
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.
Consider the following relational model for a basketball league: • Player (PlayerID, PName, Position, TeamID) •...
Consider the following relational model for a basketball league: • Player (PlayerID, PName, Position, TeamID) • Team (TeamID, TeamName, Venue) • Game (GameNo, Date, Time, HomeTeamID, AwayTeamID) • Record (GameNo, PlayerID, Points, Rebounds, Assists) In this basketball league, each team has a unique name and each player plays for only one team. One team has at least 10 players. Two teams (home team versus away team) participate in each game at home team’s venue. Each team meets all other teams...
For the given database schema. Answer the following questions. Company Database customer(cust_id, name, address) product(product_id, product_name,...
For the given database schema. Answer the following questions. Company Database customer(cust_id, name, address) product(product_id, product_name, price, quantity) transaction(trans_id, cust_id, time_date) product_trans(product_id, trans_id) Identify the primary keys and foreign keys for the relations and specify at least two different types of integrity constraints that would be applicable for different relations given.
Consider the following data.    STUDENT StudentID SName Gender Age ClubID 3234 Alfred Smith Male 20...
Consider the following data.    STUDENT StudentID SName Gender Age ClubID 3234 Alfred Smith Male 20 BSK 2244 McJohnson Robert Male 22 2389 Jessica Low Female 20 JPA 4211 Roland Devingo Male 24 4383 Jane Usa Khan Female 21 BKY 4450 Elaine Fong Female 20 JPA CLUB ClubID CName Founded Budget BKY Bakery Club 2010 2546 PDC Photomedia and Design 2005 1345 JPA Japanese Anime 2009 3453 BSK Basketball 2011 6744 If the database administrator in the University has turned...
Consider the following data.    STUDENT StudentID SName Gender Age ClubID 3234 Alfred Smith Male 20...
Consider the following data.    STUDENT StudentID SName Gender Age ClubID 3234 Alfred Smith Male 20 BSK 2244 McJohnson Robert Male 22 2389 Jessica Low Female 20 JPA 4211 Roland Devingo Male 24 4383 Jane Usa Khan Female 21 BKY 4450 Elaine Fong Female 20 JPA CLUB ClubID CName Founded Budget BKY Bakery Club 2010 2546 PDC Photomedia and Design 2005 1345 JPA Japanese Anime 2009 3453 BSK Basketball 2011 6744 What is the value returned by this SQL statement?...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT