时间:2021-07-01 10:21:17 帮助过:27人阅读
1.公式:
- 假设每页显示n条记录,当前显示的是第m页,表名是A,主键是A_id
- select top n *
- from A
- where A_id not in (select top (m-1)*n A_id from A)
2.实例演示:
- sal从高到低排序,输出1-3条记录的信息
- select top 3 * from emp order by sal desc
- sal从高到低排序,输出4-6条记录的信息
- select top 3 *
- from emp
- where sal not in (select top 3 sal from emp order by sal desc)
- order by sal desc
- sal从高到低排序,输出7-9 条记录的信息
- select top 3 *
- from emp
- where sal not in (select top 6 sal from emp order by sal desc)
- order by sal desc
- sal从高到低排序,输出10-12条记录的信息
- (因为没有第12条记录,所以只显示了2条)
- select top 3 *
- from emp
- where sal not in (select top 9 sal from emp order by sal desc)
- order by sal desc
本篇博客来自于郝斌老师视频教程的总结以及笔记的整理,仅供学习交流,切勿用于商业用途,如有侵权,请联系博主删除,博主QQ:194760901
</div>
SQL Server中的分页查询 select top
标签:商业 word 笔记 article data- phoenix use string 学习交流