取出 sql 表中第 31 到 40 的记录(以自动增长 ID 为主键)
sql server
方案 1:
select top 10 * from t where id not in (select top 30 id from t order by id ) orde by id;
方案 2:
select top 10 * from t where id in (select top 40 id from t order by id) order by id desc;
mysql
select * from t order by id limit 30, 10;
oracle
select * from (select rownum r, * from t where r <= 40) where r > 30;
分页:
pageSize=20;
pageNo = 5;
1.分页技术(直接利用 sql 语句进行分页,效率最高和最推荐的)
sql server
select top 20 * from articles id not in (select top (pageNo-1) * pageSize id from articles);
mysql
select * from articles limit (pageNo-1) * pageSize , pageSize;
oracle
select * from
(select rownum r, A.* from
(select * from articles order by postime desc) A
where rownum <= pageNo*pageSize) tmp
where r > (pageNo-1) * pageSize;
未完待续......
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于