sql基础知识:分页+排序

Oracle的分页还真是挺恶心地,不像mysql直接Limit就搞定

select name from student limit 0,20;

Oracle需要借助rownum实现:

select * 
    from (
        select s.*, rownum as rn from student s where rownum <= 10
    ) m
 where m.rn > 0

如果要增加排序,可以引入order by

select * from (
    select c.*, rownum as rn from (
        select rownum as row_num, b.* from (
            select * from student
            --这里可以写复杂的join逻辑
        ) b
        order by b.storecode desc
    ) c
    where rownum <= 10
) m
where m.rn > 0
posted @ 2016-10-17 19:07  xingoo  阅读(2557)  评论(0编辑  收藏  举报