本片博客使用的数据库表是oracle中的scott用户表;
------------------- 自然连接查询
查询 smith 的上司(两种方法)
----查询SMITH的上司 select ename from emp where empno=(select mgr from emp where ename = 'SMITH'); --自连接查询 select e1.ename, e1.mgr,e2.ename from emp e1 ,emp e2 where e1.mgr= e2.empno and E1.ename = 'SMITH';
--------------------------in的使用
---查询与部门10工作相同的员工的信息
分组查询
select ename,job,sal,deptno from emp where job in(select job from emp where deptno = 10);
-----------------------分组函数和all的查询
--查找比部门30工资高的所有员工的信息
select ename,sal,deptno from emp where sal>(select max(sal) from emp where deptno = 30);
all查询; select ename,sal,deptno from emp where sal> all(select sal from emp where deptno = 30);
--------------------函数和any
--查找比部门30任意的工资高的所有员工的信息
----使用any或者 select ename,sal,deptno from emp where sal> any ( select sal from emp where deptno = 30); ---使用函数 select ename,sal,deptno from emp where sal>( select min(sal) from emp where deptno = 30);
-----------------------------------------------------------------伪列查询 rownum rowid
---查询部分数据
-- 查询第五到第十条的数据
select ROWNUM,ename,job from(select ROWNUM r ,ename,job from emp where ROWNUM<=10) where r>5; -----MYsql + sqlite分页查询的方法 -- select * from emp limit 1,10;
-----------------------------------------------------------合并查询操作符 union ,unuion all,intersect,minus
union ,union all合并表的查询 select * from emp where job ='SALESMAN'; select * from emp where sal>1500; union的合并查询 合并并且去除重复的行 select * from emp where job ='SALESMAN' union select * from emp where sal>1500; union all的合并查询 取所有的数据 select * from emp where job ='SALESMAN' union all select * from emp where sal>1500; interseect取交集查询 select * from emp where job ='SALESMAN' intersect select * from emp where sal>1500; minus查询出来的结果是只显示在第一个结果集中存在 而不在第二个结果集重负存在的 select * from emp where job ='SALESMAN' minus select * from emp where sal>1500;