读取数据表中第m条到第n条的数据,SQL语句怎么写?

时间:2014-02-26 16:56:47   收藏:0   阅读:349
原文:读取数据表中第m条到第n条的数据,SQL语句怎么写?

对于MySQL或者Oracle来说,如果实现从Table 表中取出第 m 条到第 n 条的记录操作,我们需要TOP函数(不是所有的数据库都支持TOP函数):Select Top子句

但是,你能想到几种方法?

(1)使用not in 
Select TOP n-m+1 *  
FROM Table  
Where (id NOT IN (Select TOP m-1 id FROM Table ))    

(2)使用exists 

Select TOP n-m+1 * FROM TABLE AS a Where Not Exists 
(Select * From (Select Top m-1 * From TABLE order by id) b Where b.id=a.id ) 
order by id 


原文:http://www.cnblogs.com/lonelyxmas/p/3568125.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!