Answer the questions listed below based on our parts and supplier database. These are SQL problems. Queries should execute properly on the server. Save a
file named hw3.sql
to your T: drive folder.
Each query should be commented with the problem number and with the
problem statement below repeated. Single line comments
in an SQL file start with a # character. Also, make sure you turn in a
printout of the file.
select sno,pno from sp order by sno; # The "order by" clause is not strictly necessary.
select sno from sp where pno = 1;
select sname,status from supplier where supplier.status >= 15 and supplier.status <= 20;
select distinct sp.pno,sname from supplier inner join sp using (sno) where supplier.city = 'London';
select avg(status) from supplier;
select distinct parts.pno from parts where parts.pno not in ( select distinct parts.pno from supplier inner join sp using (sno) inner join parts using(pno) where supplier.city='London' );
select city from supplier group by city having count(city) >= 2;
Smith 1 1
. That's obvious. For ease, you can list
symmetric tuples, for example,
Smith 1 2
and Smith 2 1
.
Your answer schema should have three attributes (sname,pno,pno).
select distinct sname,pno1,pno2 from supplier, ( select sp1.sno, sp1.pno as pno1, sp2.pno as pno2 from sp as sp1, sp as sp2 where sp1.sno=sp2.sno and sp1.pno != sp2.pno ) as temp where supplier.sno=temp.sno order by sname,pno1;
select count(pno) from sp where sp.sno=1;
select sno from supplier where status < (select status from supplier where sno=1)
select sno from supplier where city = (select min(city) from supplier);
select distinct pno from supplier inner join sp using (sno) where city = 'London';
select supplier.sname, supplier.sno, parts.pno from supplier,parts where not exists (select * from sp where sp.pno = parts.pno and sp.sno = supplier.sno) order by sname,pno;