2024年5月25日发(作者:京碧琴)
设有一数据库SPJ,包含S,P,J, SPJ四个关系模式
S:供应商表 P:零件表 J:工程项目表 供应情况表
SNO PNO
SNO SNAME CITY
天津
S1 S1 P1
精益
盛锡 北京
S2
S1 P1
北京
S3
东方红
S1 P1
丰太盛 天津
S4
S1 P2
PNO PNAME COLOR WEIGHT
S2 P3
螺母红
P1 12
S2 P3
螺栓绿
P2 17
S2 P3
螺丝刀 蓝
P3 14
S2 P3
螺丝刀 红
P4
14
S2 P5
凸轮 蓝
P5 40
S2 P5
齿轮 红
P6 30
S4 P5
JNAME JNO CITY
S4 P6
一汽 长春
J1
S4 P6
弹簧厂 天津
J2
造船厂 天津
J3
颜色只能“红、绿、蓝”
唐山
J4
机车厂
纺机厂
J5
上海
工程项目名唯一
1、找出所有供应商的姓名和所在城市
2、找出所有零件的名称、颜色、重量
3、找出使用供应商S1所供应零件的工程号码
4、找出工程项目J2使用的各种零件的名称及其数量
5、找出天津厂商供应的所有零件号码
6、找出使用天津产的零件的工程名称
7、找出没有使用天津产的零件的工程号码
8、把全部红色零件的颜色改成蓝色
J4的零件P6改为由S3供应,请作必要的修改 9、由S5供给
10、从供应商关系中删除S2的记录,并从供应关系情况中删除相应的记录
11、请将(S2,J6,P4,200)插入供应关系
JNO
J1
J3
J4
J2
J1
J2
J4
J5
J1
J2
J1
J3
J4
QTY
200
100
700
100
400
200
500
400
400
100
100
300
200
12、求零件供应量大于700的供应商编号
13、找出零件供应量比S1大的供应商编号
14、求零件供应量大于700的供应商编号和供应商的姓名
1.
select sname,city
from table1
2.
select pname,color,weight
from table2
3.
select jno
from table4
where sno='s1'
4.
select pname,qty
from table2,table4
where jno='j2'and =
5.
select pno
from table1,table4
where city='天津' and =
6.
select distinct(jname)
from table1,table4,table3
where ='天津' and =
7.
select jno
from table1,table4
where = and city not in ('天津')
8.
update table2
set color='蓝'
where color='红'
9.
update table4
set sno='s3'
where sno='s5' and jno='j4' and pno='p6'
10.
delete
from table1
where sno='s2'
delete
from table4
where sno='s2'
11.
insert
into table4(sno,pno,jno,qty)
values('s2','j6','p4','200')
12.
select sno
from table4
group by sno
having sum(qty)>700
13.
select sno
from table4
group by sno
having sum(qty)>(select sum(qty) from table4 where sno='s1')
14.
select sno,sname
from table1
where sno in(
select sno
from table4
group by sno
having sum(qty)>700
)
2024年5月25日发(作者:京碧琴)
设有一数据库SPJ,包含S,P,J, SPJ四个关系模式
S:供应商表 P:零件表 J:工程项目表 供应情况表
SNO PNO
SNO SNAME CITY
天津
S1 S1 P1
精益
盛锡 北京
S2
S1 P1
北京
S3
东方红
S1 P1
丰太盛 天津
S4
S1 P2
PNO PNAME COLOR WEIGHT
S2 P3
螺母红
P1 12
S2 P3
螺栓绿
P2 17
S2 P3
螺丝刀 蓝
P3 14
S2 P3
螺丝刀 红
P4
14
S2 P5
凸轮 蓝
P5 40
S2 P5
齿轮 红
P6 30
S4 P5
JNAME JNO CITY
S4 P6
一汽 长春
J1
S4 P6
弹簧厂 天津
J2
造船厂 天津
J3
颜色只能“红、绿、蓝”
唐山
J4
机车厂
纺机厂
J5
上海
工程项目名唯一
1、找出所有供应商的姓名和所在城市
2、找出所有零件的名称、颜色、重量
3、找出使用供应商S1所供应零件的工程号码
4、找出工程项目J2使用的各种零件的名称及其数量
5、找出天津厂商供应的所有零件号码
6、找出使用天津产的零件的工程名称
7、找出没有使用天津产的零件的工程号码
8、把全部红色零件的颜色改成蓝色
J4的零件P6改为由S3供应,请作必要的修改 9、由S5供给
10、从供应商关系中删除S2的记录,并从供应关系情况中删除相应的记录
11、请将(S2,J6,P4,200)插入供应关系
JNO
J1
J3
J4
J2
J1
J2
J4
J5
J1
J2
J1
J3
J4
QTY
200
100
700
100
400
200
500
400
400
100
100
300
200
12、求零件供应量大于700的供应商编号
13、找出零件供应量比S1大的供应商编号
14、求零件供应量大于700的供应商编号和供应商的姓名
1.
select sname,city
from table1
2.
select pname,color,weight
from table2
3.
select jno
from table4
where sno='s1'
4.
select pname,qty
from table2,table4
where jno='j2'and =
5.
select pno
from table1,table4
where city='天津' and =
6.
select distinct(jname)
from table1,table4,table3
where ='天津' and =
7.
select jno
from table1,table4
where = and city not in ('天津')
8.
update table2
set color='蓝'
where color='红'
9.
update table4
set sno='s3'
where sno='s5' and jno='j4' and pno='p6'
10.
delete
from table1
where sno='s2'
delete
from table4
where sno='s2'
11.
insert
into table4(sno,pno,jno,qty)
values('s2','j6','p4','200')
12.
select sno
from table4
group by sno
having sum(qty)>700
13.
select sno
from table4
group by sno
having sum(qty)>(select sum(qty) from table4 where sno='s1')
14.
select sno,sname
from table1
where sno in(
select sno
from table4
group by sno
having sum(qty)>700
)