SQL练习题

5.

表中的数据已提前插入

use SPJ;
(1)select SNAME, CITY from St;
(2)select PNAME, COLOR, WEIGHT from P;
(3)select PNO from SPJ where SNO = 'S1';
(4)select PNAME, QTY from P, SPJ where SPJ.JNO = 'J2' and SPJ.PNO = P.PNO;
select * from St;
select * from SPJ;
select * from P;
update St set SNO = 'S4' where SNAME = '丰盛泰';
(5)select PNO from SPJ, St where SPJ.SNO = St.SNO and St.CITY = '上海';
select PNO from SPJ where SPJ.SNO in (select SNO from St where CITY = '上海'); //同上
(6)select distinct JNAME from J where JNO in (select JNO from SPJ where SNO in(select SNO from St where CITY = '上海'));
select distinct J.JNAME from J, SPJ, St where J.JNO = SPJ.JNO and SPJ.SNO = St.SNO and St.CITY = '上海';//同上
(7)select JNO from SPJ, St where St.SNO = SPJ.SNO and St.CITY = '天津'; //不会用这种表示
//select distinct JNO from SPJ where SNO not in (select SNO from St where CITY = '天津');
(8)update P set COLOR = '蓝' where COLOR = '红';
(9)update SPJ set SNO = 'S3'where SNO = 'S5' and PNO = 'P6' and JNO = 'J4';
(10)delete * from St where SNO = 'S2';
(10)delete * from SPJ where SNO = 'S2';
(11)insert into SPJ values('S2','J6','P4',200);

 

9.(1)
create view SJ as select SNO, PNO, QTY from J, SPJ where J.JNO = SPJ.JNO and J.JNAME = '三建';
select distinct * from SJ where SNO = 'S1';

posted @ 2019-04-26 14:18  kakaluotedj  阅读(178)  评论(0编辑  收藏  举报