实验二答案

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1.查询供应商号和名称,分别用小写字母和大写字母表示供应商代码。

select Lower(Sno) sno,Upper(Sno) SNO,Sname

from S;

2.查询所有供应工程零件的供应商号

select distinct sno

from spj

3.查询供应商的名称和所在城市,并按照所在城市升序排序,同一个城市的按照供应商的名称降序排序。

select sname,city

from s

order by city,sname desc;

4.查询使用供应商S1所供应零件的工程号码。

select distinct jno

from spj

where sno='s1'

5.查询零件的总个数。

select sum(Qty) '总个数'

from SPJ;

select pno,sum(Qty)

from spj

group by pno

6.查询所有以“螺”字开头的零件的零件号、零件名和颜色。

select pno,pname,color

from p

where pname like '螺%'

7.查询各个供应商供应的零件P3总数量。

select sum(qty)

from spj

where pno='p3';

select sno,sum(Qty) '总个数'

from spj

where pno='p3'

group by sno

8.供应工程J1红色零件的供应商号SNO,结果不出现重复记录。

select Sno

from SPJ inner join P

on SPJ.Pno=P.Pno and Jno='J1' and Color='红';

9.上海厂商供应的所有零件的号码。

select distinct pno

from spj,s

where spj.sno=s.sno and city='上海'

10.使用上海产的零件的工程的名称。

select Jname

from S,J,SPJ

where S.Sno=SPJ.Sno and J.Jno=SPJ.Jno and S.City='上海';

11.没有使用天津产的零件的工程号码。

select Jno

from J

where Jno not in (select distinct Jno

from S,SPJ

where S.City='天津' and S.Sno=SPJ.Sno);

--差操作

select Jno

from J

except

select distinct Jno

from S,SPJ

where S.City='天津' and S.Sno=SPJ.Sno

12.没有使用天津供应商生产的红色零件的工程号。

select Jno

from J

where Jno not in ( select distinct Jno

from S,SPJ,P

where S.Sno=SPJ.Sno and SPJ.Pno=P.Pno

and S.City='天津' and P.Color='红');

13.至少用了供应商S2所供应的全部零件的工程号Jno。

select distinct Jno

from SPJ X

where not exists ( select *

from SPJ Y

where Y.sno='s2' and not exists

( select *

from SPJ Z

where Z.Jno=X.Jno and Y.pno=Z.pno and Z.sno='s2'))

相关文档
最新文档