以前分頁習慣用這樣的SQL語句:
select * from
(select t.*,rownum row_num from mytable t order by t.id) b
where b.row_num between 1 and 10
結果發(fā)現由于該語句會先生成rownum 后執(zhí)行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
聯(lián)系客服