MySQL练习
创建数据表
第一个
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);
相关推荐
苏康申 2020-11-13
vitasfly 2020-11-12
专注前端开发 2020-10-21
oraclemch 2020-11-06
liuyang000 2020-09-25
FellowYourHeart 2020-10-05
赵继业 2020-08-17
whyname 2020-08-16
Seandba 2020-08-16
dbasunny 2020-08-16
拼命工作好好玩 2020-08-15
langyue 2020-08-15
写程序的赵童鞋 2020-08-03
Accpcjg 2020-08-02
tydldd 2020-07-30
好记忆也需烂 2020-07-28
jianghero 2020-07-28