日期:2014-05-16  浏览次数:20469 次

各个数据库取10-20条记录总结
对于mysql比较熟悉点:
select * from user limit 10,10;


对于sqlserver:
方法有三:如下
//方法一 先取前20条记录然后再去除前10条记录,不过效率不高
select top 20 from user where id not in (select top 10 from user);

//方法二 先建立自增id的临时表,然后判断10<id<20就可以了
select identity(int,1,1) as id,* into #temp from user;
select * from #temp where id between 10 and 20;

//方法三 应该比较高效了,先取前20条记录,然后将结果集倒序,取前十条就行
select top 10 from (select top 20 from user order by id) t order by t.id desc;


对于oracle则有rownum,写个高效的:
select * from (select rownum r ,u.* from user u where r<=20) where r>=10;