推理过程
输出工资最高的前三个所有员工的信息:
select top 3 * from emp order by sal desc;
工资从高到低排序,输出工资是第 4-6 的员工信息:
select top 3 *
from emp
where empo not in (select top 3 empo from emp order by sal desc)
order by sal desc
工资从高到低排序,输出工资是第 7-9 的员工信息:
select top 3 *
from emp
where empo not in (select top 6 empo from emp order by sal desc)
order by sal desc
工资从高到低排序,输出工资是第 10-12 的员工信息:
select top 3 *
from emp
where empo not in (select top 9 empo from emp order by sal desc)
order by sal desc
总结:
假设每页显示 n 条记录,当前要显示的是第 m 页。
表名 A
主键 A_id
第几页 | 排除个数 |
---|---|
1 | 0 |
2 | 3 |
3 | 6 |
4 | 9 |
select top n *
from A
where A_id not in (select top ((m-1)*n) A_id from A)
网友评论