5.7 找出没有使用天津产的零件的工程号
select Jno
from j
where not exists
(select *
from spj
where spj.jno = j.jno
and sno in
(select sno
from s
where city='天津'));
4.3 求供应工程j1零件为红色的供应商号码sno
select sno
from spj
where jno='j1' and pno in
(select pno
from p
where color='红');
select sno
from spj,p
where jno='j1' and spj.pno=p.pno
and color='红';
4.4求没有使用天津供应商生产的红色零件的工程号jno
select jno
from j
where not exists
(select *
from spj
where spj.jno=j.jno
and sno in
(select sno
from s
where city='天津')
and pno in
(select pno
from p
where color = '红'));
select jno
from j
where not exists
(select *
from spj,s,p
where spj.jno=j.jno and spj.sno=s.sno and
spj.pno=p.pno and s.city='天津' and
p.color = '红');
4.5 求至少用了供应商S1所供应的全部零件的工程号JNO
即:不存在这样的零件y,供应商s1供应了y,而工程x没有选用y
select distinct jno
from spj spjz
where not exists
(select *
from spj spjx
where sno='s1'
and not exists
(select *
from spj spjy
where spjy.pno = spjx.pno
and spjy.jno = spjz.jno));
sql嵌套查询语句练习
猜你喜欢
转载自blog.csdn.net/qq_41398619/article/details/105604599
今日推荐
周排行