Fake Solutions
Fake Solutions
Fake Solutions
semid
Semesters
ssn courseid
N
b) Professors can teach the same course in several semesters, and only the most
recent such offering needs to be recorded. (Assume this condition applies in all
subsequent questions.)
semid
Semesters
ssn courseid
1
semid
Semesters
ssn courseid
1
d) Every professor teaches exactly one course (no more, no less), and every
course must be taught by some professor.
semid
Semesters
ssn courseid
1
( ( )
π sname π sid (π pidσ color =' red ' Parts ) >< Catalog >< Suppliers )
b) Find the sids of suppliers who supply some red or green part.
(
π sid π pid (σ color =' red 'or color =' green ' Parts ) >< Catalog )
c) Find the sids of suppliers who supply some red and some green part.
( (
ρ R1, π sid (π pid σ color =' red ' Parts ) >< Catalog ))
ρ ( R2, π ( (π sid pid σ color =' green ' Parts ) >< Catalog ) )
R1 ∩ R2
e) Find the sids of suppliers who supply every red or green part.
(π sid , pid Catalog ) / (π pid σ color =' red ' or color =' green ' Parts )
3) Consider the schema presented in problem 2. Write the following queries in SQL.
a) Find the name of every part.
SELECT P.pname
FROM Parts P
b) Find the pname and cost of all parts supplied by “BMI Supply”.
c) Find the sids of suppliers who supply some red and some green part.
SELECT C.sid
FROM Parts P, Catalog C
WHERE P.color=’red’ and P.pid=C.pid
and EXISTS ( SELECT P2.pid
FROM Parts P2, Catalog C2
WHERE P2.color=’green’ and C2.sid=C.sid
and P2.pid=C2.pid )
d) Find the sids of suppliers who only supply blue parts.
( ( SELECT C.sid
FROM Catalog C, Parts P
WHERE C.pid=P.pid and P.color=’blue’ )
EXCEPT
( SELECT C2.sid
FROM Catalog C2, Parts.P2
WHERE C2.pid=P.pid and P.color <> ‘blue’ ) )
SELECT C.sid
FROM Catalog C
WHERE NOT EXISTS ( SELECT P.pid
FROM Parts P
WHERE NOT EXISTS ( SELECT C1.sid
FROM Catalog C1
WHERE C1.sid=C.sid
and C1.pid=P.pid ) )
OR
SELECT S.sid
FROM Suppliers S
WHERE NOT EXISTS ( ( SELECT P.pid
FROM Parts P )
EXCEPT
( SELECT C.pid
FROM Catalog C
WHERE C.sid=S.sid ) )