根据查询结果数据的行数,分批取出结果,比如说:我查询表a select * from a ,表a有23条记录,我想每次取出前5条,取五次结束?这个循环怎么写?和sql语句!
答:
若果你有唯一的值id可以用下面的方法: 第一次:select top 5 from a 第二次:select top 5 from a where id not in (select top 5 id from a order by id asc) 第三次:select top 5 from a where id not in (select top 10 id from a order by id asc) …… 如此下去,控制后面那个子查询top的数量就行了。