zoukankan      html  css  js  c++  java
  • oracle 分页的sql语句

    已知有两种方法效率上貌似第一种更优:

    1、

    select * from
    (
    select t1.*, rownum n
    from (select * from cm_log order by oper_time desc) t1
    where rownum <= 5000
    ) b where b.n >5;

    注:rownum 和 order by 同时出现在where 语句中时除非 order by 的主键否则都是按先执行rownum后排序,所以这里用了先子查询排序在执行rownum条件, 还有个用子查询的原因是 取ownum n这个伪列 只有子查询才能取出1.2.3.。这样的否则是取得本来的rownum。

    2、

    select * from (select * from cm_log order by oper_time desc) where rownum<=5000
    minus
    select * from (select * from cm_log order by oper_time desc) where rownum<=5

    注:r不能用大于号, 百度解释说rownum > 5这样的条件找第一行rownum是1不符合,到第二行时rownum又变成了1所以永远查不出来数据。

  • 相关阅读:
    springmvc
    POJ 3683 Priest John's Busiest Day
    POJ 3678 Katu Puzzle
    HDU 1815 Building roads
    CDOJ UESTC 1220 The Battle of Guandu
    HDU 3715 Go Deeper
    HDU 3622 Bomb Game
    POJ 3207 Ikki's Story IV
    POJ 3648 Wedding
    HDU 1814 Peaceful Commission
  • 原文地址:https://www.cnblogs.com/xizhenghe/p/7889127.html
Copyright © 2011-2022 走看看