SQL Server中选出指定范围行的SQL语句代码


在数据库查询的时候,我们有时有这样的需求,就是要找出数据表里指定范围行内的数据记录,比如说要找出数据表里第10行到第20行的这10条数据,那么我们怎么来实现呢?

按照通常的方法是实现不了的,我们得借助于临时表以及一个函数来实现


代码如下:


Select no=Identity(int,1,1),* Into #temptable From dbo.teacher_info order by teacher_name--利用Identity函数生成记录序号


Select * From #temptable Where no>=10 And no < 20


Drop Table #temptable--用完后删除临时表


这样我们就实现了我们的目的。

« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3