mysql多表操作2 多表查询

来源:互联网 发布:淘宝木子禅佛珠怎么样 编辑:程序博客网 时间:2024/05/17 02:44

多表的定义:mysql多表操作1以及存储过程的应用

表中的信息:

学生表:

教师表:

课程表:

选课表(成绩表):


(1)查询选了课的学生所有信息:

select * from studentwhere id in(select Sid from SC);
结果:

(2)查询成绩已经出来了的学生的全部信息:

成绩没出来默认为null

 select *from student where id in( select Sid from SC where score is not null);
结果:

查询学号为“B1000”的学生选了多少门课

select count(*) as 课程数 from SCwhere Sid="B1000";

结果:

查询学号为“B1000”的学生选了哪些课程

 select Cname from course where cid in( select Cid from SC where Sid="B1000");

结果:


查询学号为“B1000”的学生选了那些课程的老师信息

select * from teacherwhere Tid in( select Tid from course where Cid in (         select Cid from SC         where Sid="B1000" ));
结果:

查询选修了C++这门课的学生姓名:

select name as 姓名 from studentwhere id in(select Sid from SCwhere Cid in(select Cid from coursewhere Cname="C++语言"));
结果: