zoukankan      html  css  js  c++  java
  • use ROW_NUMBER() for pagination in Oracle and SQLServer

    ------------------------------------------------------------------------Oracle------------------------------------------------------

    C:Userswilliam.tang>sqlplus / as sysdba
    SQL*Plus: Release 11.2.0.1.0 Production on Wed Nov 20 16:43:33 2013
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.

    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options

    SQL> conn oe/oe
    Connected.

    SQL> select * from (select cust_first_name,customer_id, row_number() over(order by customer_id) row_num from customers) tmp where row_num between 10 and 20;

    CUST_FIRST_NAME      CUSTOMER_ID    ROW_NUM
    --------------------        -----------           ----------
    Charlie                          110                       10
    Charlie                          111                       11
    Guillaume                      112                       12
    Daniel                           113                       13
    Dianne                           114                       14
    Geraldine                      115                       15
    Geraldine                      116                       16
    Guillaume                     117                       17
    Maurice                       118                       18
    Maurice                       119                       19
    Diane                           120                       20

    11 rows selected.

    ---------------------------------------------------------------------Sqlserver-----------------------------------------------------------


    SELECT contact_id,custno,Fdate FROM
        (SELECT ROW_NUMBER() OVER (ORDER BY contact_id) AS Row,custno, contact_id, Ftype, Fdate
         FROM gpcomp1.GPCUST where CUSTNO < '40356') AS EMP
    WHERE Row BETWEEN 20 AND 30

    contact_id    custno    Fdate
    3627    35004010    99999999
    4228    35005544    20070315
    4382    35005874    20061203
    4664    35006666    20120102
    5108    35007869    20070307
    5162    35008023    20080906
    6271    35010452    20070311
    6555    35010972    20070308
    6581    35011037    20070308
    6752    35011375    20070309
    7013    350118&66    20070601

  • 相关阅读:
    CF785CAnton and Permutation(分块 动态逆序对)
    Codeforces617E XOR and Favorite Number(分块 异或)
    POJ2155 Matrix(二维树状数组||区间修改单点查询)
    阿里云重磅发布数据库专家服务
    Dataphin公共云重磅发布,提供一站式智能数据构建与管理能
    阿里大数据产品Dataphin上线公共云,将助力更多企业构建数据中台
    快速完成智能数据构建,Dataphin公共云版本全面解读
    微服务开源生态报告 No.1
    分享 KubeCon 2019 (上海)关于 Serverless 及 Knative 相关演讲会议
    MaxCompute 费用暴涨之存储压缩率降低导致SQL输入量变大
  • 原文地址:https://www.cnblogs.com/princessd8251/p/3433896.html
Copyright © 2011-2022 走看看