数据库的分页
查询工资最高的前5名员工
select e.* from (select salary from employ order by
salary desc) e where rownum<=5;
先定义rownum,用between and分页,效率不是最高的
查询员工中第6条到第12条的记录
select * from (select rownum rum,e.* from employee e)
where rum between 6 and 12;
效率比较高不用先查找整个表
select * from(select rownum rum,e.* from employee e
where rownum<=12) where rum>=6;
多行子查询:返回多行
in等于列表中任何一个 逻辑或
any和子查询返回的任意一个值比较 逻辑或比较
all 和子查询返回的所有值比较 逻辑与
IN代表逻辑或
select * from employees where employee_id in (
select manager_id from departments)
多行子查询中使用ANY 操作符 查询大于60号部门的任何一个员工的工资 ALL 代表大于最大的
select * from
employees where salary >any (select salary
from employees where department_id=60)
多行子查询中使用 ALL 操作符
SELECT employee_id, last_name, job_id, salary FROM
employees WHERE salary < ALL(SELECT
salary FROM employees WHERE job_id = 'IT_PROG') AND
总结:all是大于最大的,any是大于最小的