SELECT *
FROM S
WHERE A=10;
(2)
SELECT A,B
FROM S;
(3)
SELECT A,B,S.C,S.D,E,F
FROM S,T
WHERE S.C=T.C AND S.D=T.D
(4)
SELECT S.*,T.*
FROM S,T
WHERE S.C=T.C;
(5)
SELECT *
FROM S,T
WHERE A
(6)
SELECT S1.C,S1.D,T.C,T.D,E,F
FROM T,(SELECT DISTINCT C,D
FROM S)
AS S1
CREATE TABLE SPJ(SNO CHAR(4),
PNO CHAR(4),
JNO CHAR(4),
QTY SMALLINT
);
INSERT INTO SPJ(SNO,PNO,JNO,QTY) VALUES('S1','P1','J1',200);
INSERT INTO SPJ(SNO,PNO,JNO,QTY) VALUES('S1','P1','J3',100);
INSERT INTO SPJ(SNO,PNO,JNO,QTY) VALUES('S1','P1','J4',700);
INSERT INTO SPJ(SNO,PNO,JNO,QTY) VALUES('S1','P2','J2',100);
INSERT INTO SPJ(SNO,PNO,JNO,QTY) VALUES('S2','P3','J1',400);
INSERT INTO SPJ(SNO,PNO,JNO,QTY) VALUES('S2','P3','J2',200);
INSERT INTO SPJ(SNO,PNO,JNO,QTY) VALUES('S2','P3','J4',500);
INSERT INTO SPJ(SNO,PNO,JNO,QTY) VALUES('S2','P3','J5',400);
INSERT INTO SPJ(SNO,PNO,JNO,QTY) VALUES('S2','P5','J1',400);
INSERT INTO SPJ(SNO,PNO,JNO,QTY) VALUES('S2','P5','J2',100);
INSERT INTO SPJ(SNO,PNO,JNO,QTY) VALUES('S3','P1','J1',200);
INSERT INTO SPJ(SNO,PNO,JNO,QTY) VALUES('S3','P3','J1',200);
INSERT INTO SPJ(SNO,PNO,JNO,QTY) VALUES('S4','P5','J1',100);
INSERT INTO SPJ(SNO,PNO,JNO,QTY) VALUES('S4','P6','J3',300);
INSERT INTO SPJ(SNO,PNO,JNO,QTY) VALUES('S4','P6','J4',200);
INSERT INTO SPJ(SNO,PNO,JNO,QTY) VALUES('S5','P2','J4',100);
INSERT INTO SPJ(SNO,PNO,JNO,QTY) VALUES('S5','P3','J1',200);
INSERT INTO SPJ(SNO,PNO,JNO,QTY) VALUES('S5','P6','J2',200);
INSERT INTO SPJ(SNO,PNO,JNO,QTY) VALUES('S5','P6','J4',500);
1)求供应工程J1零件的供应商号码SNO;
SELECT DISTINCT SNO FROM SPJ WHERE JNO='J1';
2)求供应工程J1零件P1的供应商号码SNO;
SELECT DISTINCT SNO FROM SPJ WHERE JNO='J1'AND PNO='P1';
3)求供应工程J1零件为红色的供应商号码 SNO;
SELECT SNO
FROM SPJ,P
WHERE P.PNO=SPJ.PNO AND JNO='J1' AND COLOR='红';
4)求没有使用天津供应商生产的红色零件的工程号JNO;
SELECT JNO
FROM J
WHERE NOT EXISTS(
SELECT *
FROM SPJ,S,P
WHERE S.CITY='天津' AND P.COLOR='红' AND SPJ.JNO=J.JNO AND SPJ.SNO=S.SNO AND SPJ.PNO=P.PNO);
5)求至少用了供应商S1所供应的全部零件的工程号JNO;
SELECT SPJ.JNO
FROM SPJ
WHERE NOT EXISTS
(SELECT *
FROM S
WHERE NOT EXISTS
(SELECT *
FROM P
WHERE P.PNO=SPJ.PNO
AND SPJ.SNO=S.SNO
)
)
5.(1)
SELECT SNAME,CITY FROM S;
(2)
SELECT PNAME,COLOR,WEIGHT
FROM P;
(3)
SELECT JNO FROM SPJ WHERE SNO='S1';
(4)
SELECT P.PNAME,SPJ.QTY FROM P,SPJ WHERE P.PNO=SPJ.PNO AND SPJ.JNO='J2';
(5)
SELECT SPJ.PNO FROM S,SPJ WHERE S.SNO=SPJ.SNO AND S.CITY='上海';
(6)
SELECT J.JNAME
FROM J,S,SPJ
WHERE S.SNO=SPJ.SNO AND S.CITY='上海'AND J.JNO=SPJ.JNO;
(7)
SELECT JNO
FROM J
WHERE JNO NOT IN(
SELECT JNO
FROM SPJ
WHERE SNO IN(SELECT SNO
FROM S
WHERE 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 SPJ WHERE SNO='S2';
(11)
INSERT INTO SPJ VALUES('S2','P4','J6',200)
CREATE VIEW VIEW_SPJ
AS
SELECT SNO,PNO,QTY
FROM SPJ
WHERE JNO=(SELECT JNO
FROM J
WHERE JNAME='三建')
1)找出三建工程项目使用的各种零件代码及其数量;
SELECT PNO,QTY
FROM VIEW_SPJ
2)找出供应商S1的供应情况;
SELECT *
FROM SPJVIEW
WHERE SNO='S1'