供应表的简单查询

--插入数据

INSERT INTO S values ('S1','海南公司','海口');
INSERT INTO S values ('S2','云南公司','昆明');
INSERT INTO S values ('S3','杭州公司','杭州');
INSERT INTO S values ('S4','北京公司','北京');

INSERT INTO P values ('P1','绿茶','1');
INSERT INTO P values ('P2','绿茶','2');
INSERT INTO P values ('P3','普洱茶','1');
INSERT INTO P values ('P4','花茶','1');
INSERT INTO P values ('P5','红茶','1');

INSERT INTO SP values ('S1','P1',100); 
INSERT INTO SP values ('S2','P3',200);
INSERT INTO SP values ('S2','P5',100);
INSERT INTO SP values ('S3','P1',400);
INSERT INTO SP values ('S3','P2',500);
INSERT INTO SP values ('S4','P4',200);

--求供应产品编号为P1的供应商编号
select sno from sp where pno='P1';
--求供应绿茶等级为1的供应商编号
select pno from P where pname='绿茶' and kind =1;
select sno from sp  where pno='P1';
--求没有使用北京公司供应商的茶叶,但产品级别是1级茶叶的产品编号
select sno from s where sname='北京公司';
select pno from sp where sno<>'S4';
select pno from p where (pno='P1' or pno='P2' or pno='P3' or pno='P5') and kind=1;

你可能感兴趣的:(查询)