oracle用rownum会与排序order by 产生冲突

需要用rownum和order by时可以用两层select进行查询
select *
    from(select rownum rn, a.* from
    (select DISTINCT c.name AS cname, NVL(sum(oi. money),0) AS sumMoney
                from (orders o inner join customers c on o.customer_id=c.id)
                 left join order_items oi
                  on o.id=oi.order_id
                     where   '1'='1'   
                         group by c.name
                           order by sumMoney desc
      ) a)
    where RN >  0 and RN < 4

posted @ 2017-09-28 15:05  燕大梁朝伟  阅读(1106)  评论(0编辑  收藏  举报