笛卡尔积:
笛卡尔积
连接的类型:
1、等值连接
2、不等值连接
3、外连接
4、自连接
统计员工信息:部门号 部门名称 人数
select emp.deptno,dept.dname,count(*) 人数
from emp,dept
where emp.deptno=dept.deptno
group by emp.deptno,dept.dname;//这个方法我感觉不好
//分组应该按dept.dept来分
select dept.deptno,dept.dname, count(emp.empno)
from emp,dept
where emp.deptno=dept.deptno
group by dept.deptno,dept.dname;//实际上以上这两种方法都是错的。
因为在emp表中有一个部门是没有出现的
where 左边的表是左表,右边的表是右表
加号不在哪个表,哪个表就全部显示
自连接:产生的数据太大了
查询 员工姓名 老板姓名
自连接
层次查询
伪列:level。层次查询的伪列