我想按顺序显示行号

问题描述 投票:0回答:1

除了行号,我已经完成了我的SQL查询。我想显示行号例如

  | # | VENDOR NAME  | VENDOR BALANCE |
  +---+--------------+----------------+
  | 1 | VendorName_1 |     Balance1   |
  | 2 | VendorName_2 |     Balance2   |
  | 3 | VendorName_3 |     Balance3   |
  | 4 | VendorName_4 |     Balance4   |

这是我的查询:

 SELECT * 
 FROM ( SELECT xsl.VENDOR_NAME
               , nvl(xsl.DR , 0) - nvl(xsl.CR , 0) Balance
               , ROW_NUMBER() OVER(PARTITION BY nvl(xsl.DR , 0) - nvl(xsl.CR , 0) ORDER BY  nvl(xsl.DR , 0) - nvl(xsl.CR , 0)) rank_max 
        FROM xxng_supp_ledger xsl) 
 ORDER BY rank_max 
sql database oracle report
1个回答
0
投票

您可以在外部查询中使用ROW_NUMBER分析函数,如下所示:

SELECT ROW_NUMBER() OVER (ORDER BY rank_max) AS RN, T.* FROM (
        SELECT
          xsl.VENDOR_NAME, 
           nvl(xsl.DR , 0) - nvl(xsl.CR , 0) Balance
         ,ROW_NUMBER() OVER(PARTITION BY nvl(xsl.DR , 0) - nvl(xsl.CR , 0) ORDER BY  nvl(xsl.DR , 0) - nvl(xsl.CR , 0)) rank_max 
        FROM xxng_supp_ledger xsl
      ) T
      ORDER BY rank_max

干杯!

© www.soinside.com 2019 - 2024. All rights reserved.