數據庫系統概論課后SQL語句習題


 

 

 P70. 6

(1)求供應工程J1零件的供應商號碼SNO

select Sno from SPJ where JNO = ‘J1’  

(2)求供應工程J1零件P1的供應商號碼SNO

select SNo from SPJ where Jno = ‘J1’ and PNO = ‘P1’

(3)求供應工程J1零件為紅色的供應商號碼SNO

select SNO from SPJ where PNO IN (select PNO from P where COLOR='')

(4)求沒有使用天津供應商生產的紅色零件的工程號JNO

select * from SPJ where SNO IN(select SNO from S where CITY='天津') 
and PNO IN(select PNO from P where COLOR='')

(5)求至少使用了供應商S1所供應的全部零件的工程號JNO

select * from SPJ where exists(select * from SPJ where SNO='S1')

 

P130. 5

(1)找出所有供應商的姓名和所在城市

select SNAME,CITY from S

(2)找出所有零件的名稱、顏色、重量

select PNAME,COLOR,WEIGHT from P

(3)找出使用供應商S1所供應零件的工程號碼

select JNO from SPJ where SNO = 'S1'

(4)找出工程項目J2使用的各種零件的名稱及其數量

select P.PNAME AS NAME,count(SPJ.JNO) AS NUM from SPJ,P where SPJ.JNO='J2' and SPJ.PNO = P.PNO group by P.PNAME

(5)找出上海廠商供應的所有零件號碼

select distinct PNO from SPJ where SNO IN(select SNO from S where CITY='上海')

(6)找出使用上海產的零件的工程名稱

select distinct JNO from SPJ where SNO =(select SNO from S where CITY='上海')

(7)找出沒有使用天津產的零件的工程號碼

select distinct JNO from SPJ where SNO not in(select SNO from S where CITY='天津')

(8)把全部紅色零件的顏色改成藍色

update P set COLOR = ‘藍‘ where COLOR = ‘紅’

(9)由S5供給J4的零件P6改為由S3供應,請做出必要的修改

update SPJ set SNO='S3' where SNO='S5' AND PNO='P6'

(10)從供應商關系中刪除S2的記錄,並從供應情況關系中刪除相應的記錄

delete from SPJ where SNO='S2'

delete from S where SNO='S2'

(11)請將(S2,J6,P4,200)插入供應情況關系

insert into SPJ(SNO,JNO,PNO,QTY) values('S2','J6','P4',200)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM