hanshangzhi 2020-01-12
创建数据表
第一个
create table stu( sno int auto_increment, snname varchar(20), ssex varchar(10), cno int, primary key(sno) );
第二个
create table class( cno int auto_increment, sname varchar(20), primary key(cno) );
第三个
create table score( id int auto_increment, cno varchar(20), degree varchar(10), primary keyo(id) );
插入数据
insert into 表名(字段名1,字段名2) values (数据1,数据2);
1.找出学习oracle的学生信息
select * from stu as s join score as o on s.sno = o.sno join class as c on c.cno = o.cno where c.cname = ‘oracle‘;
2.查出姜正国的信息和所学专业
select c.cname from stu as s join score as o on s.sno = o.sno join class as c on c.cno = o.cno where s.sname = ‘jiangzhengguo‘;
3找出只学了一门的同学信息
select * from stu where sno=(select cno from score group by cno having count(*)=1);
4找出学了三门以上的同学信息
select * from stu where sno=(select cno from score group by cno having count(*)>=3);