一、表的加法:union


如果想保留两个表中的重复值,那么使用union all,那么重复值语文课程就被保留下来了


二、表的联结
- 交叉联结(也叫笛卡尔积 cross jion)
表中的每一行与另一个表中的每一行合并在一起,产生的行数是两个表行数的乘积,它的数据产生如下图所示

2.内联结(inner join):查找出同时存在于两张表的数据


3.左联结(left join):取出左边表的全部数据,右边的表选出与左边相同数据的行,然后进行数据合并


如果我想查找在左表中有而在右表中没有的数据


4、右联结


如果我想查找在右表中有而在左表中没有的数据


5、全联结(full join)—取出左表和右表的所有数据,有相同数据就合并,没有则用Null来填充
- MySQL是不支持全联结的
总结:

三、案例应用




四、case表达式—相当于条件判断函数

案例1.查询score表中学生的成绩是否及格

案例2.查询每门课程的及格人数和不及格人数

案例3.使用分段[100-85],[85-70][70-60],[<60]来统计各分段人数,课程号,课程名称
