加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sqlserver、mysql、oracle分页

发布时间:2020-12-12 15:41:34 所属栏目:MsSql教程 来源:网络整理
导读:SQL server分页: select top pageSize * from products where productID not in (select top (pageindex-1)*pageSize productId? from products order by ProductID asc) order by ProductID asc ? MySql分页: select * from tableName limit 10,20 oracle

SQL server分页:

select top pageSize * from products where productID not in(select top (pageindex-1)*pageSize productId? from products order by ProductID asc) order by ProductID asc

?

MySql分页:

select * from tableName limit 10,20


oracle 分页(转自:http://www.blogjava.net/joessy/articles/1398.html)

以前分页习惯用这样的SQL语句:

select * from

(select t.*,rownum row_num from mytable t order by t.id)?b

where b.row_num between 1 and 10

结果发现由于该语句会先生成rownum 后执行order by 子句,因而排序结果根本不对,后来在GOOGLE上搜到一篇文章,原来多套一层select 就能很好的解决该问题,特此记录,语句如下:

select * from

(select a.*,rownum row_num from

(select * from?mytable t order by t.id desc) a

) b where b.row_num between 1 and 10

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读