3、
(1)SELECTFROM S WHERE A=10;
(2)SELECT A,B FROM S
(3)SELECTFROM S INNER JOIN T ON S.C=T.C AND S.D=T.D
(4)SELECTFROM S INNER JOIN T ON S.C=T.C
(5)SELECTFROM S INNER JOIN T ON S.A<S.E
(6)SELECT*FROM S,T WHERE S.C=T.C AND T.D=S.D
4、S表:S(SNO,SNAME,STATUS,CITY);
建表:CREATETABLES(SnoC(2)UNIQUE,SnameC(6),StatusC(2),CityC(4));
P表:P(PNO,PNAME,COLOR,WEIGHT);
建表:CREATETABLEP(PnoC(2)UNIQUE,PnameC(6),COLORC(2),WEIGHTINT);
J表:J(JNO,JNAME,CITY);
建表:CREATETABLEJ(JnoC(2)UNlQUE,JNAMEC(8),CITYC(4))
sPJ表:sPJ(sNo,PNo,JNo,QTY);
建表:SPJ(SNO,PNO,JNO,QTY)CREATETABLESPJ(SnoC(2),PnoC(2),JNOC(2),QTYINT))
查询:
(1)求供应工程 Jl 零件的供应商号码 SNO ;
SELECT DIST SNO FROM SPJ WHERE JNO=‘J1’
(2)求供应工程 Jl 零件 Pl 的供应商号码 SNO ;
SELECT DIST SNO FROM SPJ WHERE JNO=‘J1’ AND PNO=‘P1’
(3)求供应工程 Jl 零件为红色的供应商号码 SNO ;
SELECT SNO FROM SPJ,P WHERE JNO=‘J1’ AND SPJ.PNO=P.PNO AND COLOR=‘红’
(4)求没有使用天津供应商生产的红色零件的工程号JNO;
SELECT DIST JNO FROM SPJ WHERE JNO NOT IN(SELECT JNO FROM SPJ,P,S WHERE S.CITY=‘天津’ AND COLOR=‘红’ AND S.SNO=SPJ.SNO AND P.PNO=SPJ.PNO)
(5)求至少供应商S1所供应的全部零件的工程号JNO;
1、查询S1供应商所提供零件号
SELECT DIST PNO FROM SPJ WHERE SNO=‘S1’
结果:(P1,P2)
2、查询哪个工程既用P1又用P2
SELECT JNO FROM SPJ WHERE PNO=‘P1’ AND JNO IN (SELECT JNO FROM SPJ WHERE PNO=‘P2’)
5、
(1)SELECT SNAME,CITY FROM S
(2)SELECT PNAME,COLOR WEIGHT FROM P
(3)SELECT DIST JNO FROM SPJ WHERE SNO=‘S1’
(4)SELECT PNAME,QTY FROM SPJ,P WHERE P.PNO=SPJ.PNO AND SPJ.JNO=‘J2’
(5)SELECT PNO FROM SPJ,S WHERE S.SNO=SPJ.SNO AND CITY=‘上海’
(6)SELECT JNAME FROM SPJ,S,J WHERE S.SNO=SPJ.SNO AND S.CITY=‘上海’ AND J.JNO=SPJ.JNO
(7)SELECT DIST JNO FROM SPJ,S WHERE S.SNO=SPJ.SNO AND S.CITY<>‘天津’
(8)UPDATE P SET COLOR=‘蓝’ WHERE COLOR=‘红’
(9)UPDATE SPJ SET SNO=‘S3’ WHERE SNO=‘S5’ AND JNO=‘J4’ AND PNO=‘P6’
(10)DELETE FROM S WHERE SNO=’S2’
DELETE FROM SPJ WHERE SNO=’S2’
(11)INSERT INTO SPJ VALUES(‘S2’,‘J6’,‘P4’,200)
9、
(1)SELECT DIST PNO,QTY FROM VSP
(2)SELECT DIST * FROM VSP WHERE SNO=‘S1’