School of Computer Science 60-315-01 Quiz 1 Fall '06 - 03-60-315

advertisement
School of Computer Science 60-315 Quiz 2
Answers
1. 10 marks. Get the S# for suppliers who supply both part P1and part P4.
sx.sname where  spjx  spjy s.t.
spjx.s# = sx.s# &
spjy.s# = sx.s# &
spjx.p# = P1 &
spjy.p# = P4
2. 10 marks. Get the sname for suppliers who supply a red part to a project in London.
sx.sname where  spjx  px  jx s.t.
spjx.s# = sx.s# &
spjx.p# = px.p# &
spjx.j# = jx.j# &
px.colour = red &
jx.city = London
3. 10 marks. Get the S# for suppliers who do not supply a red part.
sx.s# where not  spjx px s.t.
sx.s# = spjx.s# & px.colour = red
4. 10 marks. Get the S# for suppliers who supply to all the projects.
sx.s# where  jx  spjx s.t.
sx.s# = spjx.s# &
jx.j# = spjx.j#
5. 10 marks. Get the S# for suppliers who supply to all the London projects.
sx.s# where  jx (if jx.city = London) then  spjx s.t.
spjx.s# = sx.s# &
spjx.j# = jx.j#
6. 10 marks. Get the Sname for suppliers who supply all the red parts to all projects.
sx.sname where  px  jx (if px.colour = red ) then  spjx s.t.
spjx.s# = sx.s# &
spjx.p# = px.p# &
spjx..j# = jx.j#
7. 10 marks. Get the sname for suppliers who supply only London projects.
sx.sname where spjx jx ( if jx.city London) then
spjx.s# = sx.s# &
spjx.j# = jx.j#
1
SQL questions:
8. 10 marks. Get the s# or suppliers who supply both P1 and P4. MUST be done using a
subquery.
SQL> select sno
2 from spj
3 where pno = 'P1' and sno in
4 (select sno
5 from spj
6 where pno = 'P4');
SNO
--S5
SQL>
9. 10 marks. What is the maximum number of shipments and the average QTY of parts shipped
by each supplier? You must show the supplier number as part of your answer.
SQL> select sno, count(pno), avg(qty)
2 from spj
3 group by sno;
SNO COUNT(PNO) AVG(QTY)
--------------------S1
2
450
S2
8
400
S3
2
350
S4
2
300
S5
10
310
SQL>
10. 10 marks. Get the S# and status of suppliers whose status is less than the average
status of all suppliers.
SQL> select sno, status
2 from s
3 where status < (select avg(status) from s);
SNO
--S1
S2
S4
STATUS
---------20
10
20
SQL>
2
3
Download