zoukankan      html  css  js  c++  java
  • 各类数据库分页SQL语法

    一. Mysql分页SQL语法

    收到客户端{pageNo:1,pagesize:10}
    select * from table limit (pageNo-1)*pageSize, pageSize;
    select * from table limit pageSize offset (pageNo-1)*pageSize;
    
    select * from table limit 0, 10;
    select * from table limit 10 offset 0;
    

    二. Apache Doris分页SQL语法

    需要 order by 字段

    收到客户端{pageNo:1,pagesize:10}
    select * from table order by ID limit pageSize offset (pageNo-1)*pageSize;
    
    select * from table order by ID limit 10 offset 0;
    

    三. PostgreSql分页SQL语法

    收到客户端{pageNo:1,pagesize:10}
    select * from table limit pageSize offset (pageNo-1)*pageSize;
    
    select * from table limit 10 offset 0;
    

    四. Apache Impala分页SQL语法

    需要 order by 字段

    收到客户端{pageNo:1,pagesize:10}
    select * from table order by ID limit pageSize offset (pageNo-1)*pageSize;
    
    select * from table order by ID limit 10 offset 0;
    

    五. Oracle分页SQL语法

    返回会多出一个字段row_id

    收到客户端{pageNo:1,pagesize:10}
    select *
      from (select tmp_page.*, rownum def_row_id
              from ( SELECT * FROM table_name ) tmp_page
            where rownum <= pageNo*pagesize)
    where def_row_id > (pageNo-1)*pageSize;
    
    select *
      from (select tmp_page.*, rownum def_row_id
              from ( SELECT * FROM table_name ) tmp_page
            where rownum <= 10)
    where def_row_id > 0;
    

    六. Teradata分页SQL语法

    需要 order by 字段

    收到客户端{pageNo:1,pagesize:10}
    select * from table_name
    qualify row_number() over(order by id) > (pageNo-1)*pageSize and row_number() over(order by id) <= pageNo*pagesize;
    
    select * from table_name
    qualify row_number() over(order by id) > 0 and row_number() over(order by id) <= 10;
    
  • 相关阅读:
    数据库空间使用情况
    创建database link
    oracle导出指定几张表的数据以逗号等为分隔符
    Oracle手工创建实例
    通过shell脚本调用oracle存储过程并加入定时任务
    oracle导出与导入脚本
    在存储过程中为表添加月分区与日分区
    oracle添加分区
    ORACLE_SID与SID区别
    AUTHID DEFINER与AUTHID CURRENT_USER
  • 原文地址:https://www.cnblogs.com/levi125/p/15252221.html
Copyright © 2011-2022 走看看