【正文】
INTO Supply(Sid,Pid,Cost)VALUES(39。S339。,39。P239。,200)。 INSERT INTO Supply(Sid,Pid,Cost)VALUES(39。S439。,39。P239。,200)。 INSERT INTO Supply(Sid,Pid,Cost)VALUES(39。S439。,39。P439。,300)。 INSERT INTO Supply(Sid,Pid,Cost)VALUES(39。S439。,39。P539。,400)。 五、查詢 1. 查找有供應(yīng)商供應(yīng)的零件的名字 源程序 : select distinct PNAME from Parts,Supply where =。 結(jié)果: PNAME Bolt Cam Cog Nut Screw 2. 查找供應(yīng)所有零件的供應(yīng)商名字 源程序 : select sname from suppliers where not exists (select * from parts where not exists (select * from supply where sid= and pid=))。 結(jié)果: sname Smith 3. 查找供應(yīng)所有紅色零件的供應(yīng)商名字 源程序 : select distinct sname from suppliers,parts,supply where = and = and color=39。red39。 結(jié)果: sname Clark Jones Smith 4. 查找僅由“ Smith”供應(yīng)的零件名字 源程序 : select pname from suppliers,parts,supply where = and = and sname=39。smith39。 結(jié)果: pname Nut Bolt Screw Screw Cam Cog 5. 查找供應(yīng)某些零件的價(jià)格高于同種零件價(jià)格平均值的供應(yīng)商編號(hào) sid 源程序 : select sid ,pid from supply supply1 where cost (select avg(cost) from supply supply2 where =) 結(jié)果: sid pid S1 P1 S1 P3 S2 P2 S4 P5 6. 查找每種零件中供應(yīng)價(jià)格最貴的供應(yīng)商名字 源程序 : select sid ,pid ,cost from supply supply1 where cost = (select max(cost) from supply supply2 where =) 結(jié)果: sid pid cost S1 P3 400 S2 P2 400 S3 P2 200 S4 P5 400 7. 查找僅供應(yīng)紅色零件的供應(yīng)商名字 源程序 : select distinct sname from suppliers,parts,supply where = and = and color=39。red39。 結(jié)果: sname Clark Jones Smith 8. 查找供應(yīng)紅色和綠色零件的供應(yīng)商名字 源程序 : select sname from suppliers,parts,supply where color=39。Red39。 and sname in (select sname from suppliers,parts,supply where color=39。Green39。) and = and = 。 結(jié)果: sname Smith Jones Clark 9. 查找供應(yīng)紅色或綠色零件的供應(yīng)商名字 源程序 : select distinct sname from suppliers,parts,supply where = and = and color=39。red39。 or color=39。green39。 結(jié)果: sname Smith Jones Black Clark