CS 649 Database Management Systems Assignment #1 Solutions 1. Get the names of all suppliers select sname from s 2. Get the names of parts whose weight is between 10 and 15 select pname,weight from p where weight between '10' and '15' select pname from p where weight >'10' and weight<'15' 3. Which supplier supplied what parts to the 'Sorter' job? select s.sname,p.pname from s,p,j,spj where s.sno=spj.sno and p.pno=spj.pno and j.jno=spj.jno and j.jname='Sorter' 4. Which jobs require red parts? select distinct j.jname from p,j,spj where j.jno=spj.jno and p.pno=spj.pno and p.color='red' 5. Get the names of the suppliers who supplied in 1998 and 1999 select sname from s where sno in ( select sno from spj where year(shipDate)=1999 and sno in( select sno from spj where year(shipDate)=1998)) 6. Get the names of the suppliers who never supplied anything in 1999 select sname from s where sno in (select distinct sno from spj where year(shipDate)<>1999) 7. Which supplier supplied the most parts ever? select sname from s where sno in (select distinct sno from spj where qty=(select max(qty) from spj)) 8. What is the total quantity of parts ordered for the 'Sorter' job? select sum(qty) from spj where jno in(select jno from j where jname='Sorter') 9. What are the parts that 'Adam' ever supplied? select distinct p.pname from s,p,spj where s.sno=spj.sno and p.pno=spj.pno and s.sname='Adam' Page 1 CS 649 Database Management Systems 10. What is the most recently shipped job? select jname from j where jno in (select jno from spj where shipDate=(select max(shipDate) from spj)) 11. What is the total weight of a 'Terminal'? select sum(p.weight*spj.qty) from p,spj,j where j.jno=spj.jno and p.pno=spj.pno and j.jname='Terminal' 12. Which supplier has the lowest status? select sname from s where status = (select min(status) from s) 13. What is the total weight of all the parts? select sum(weight) from p 14. Which of the jobs had all the parts from the same city? select distinct j.jname from j,p,spj where j.jno=spj.jno and p.pno=spj.pno and j.city=p.city 15. Get the names of the parts required to finish the 'Tape' job select distinct p.pname from j,p,spj where j.jno=spj.jno and p.pno=spj.pno and j.jname='Tape' 16. Which city had the maximum number of parts originating from it? select name from (select sum(spj.qty) as y,p.city as name from p,spj where p.pno=spj.pno group by p.city) where y=(select max(x) from (select sum(spj.qty) as x,p.city from p,spj where p.pno=spj.pno group by p.city)) Page 2