zoukankan      html  css  js  c++  java
  • listagg 行转列

    select a.consumer,a.status,count(*) from (select /*+ parallel(t 8)*/
     p.description as consumer,
     case t.respcode
       when '000000' then
        '成功'
       when '01' then '成功'
       else
        '失败'
     end as status
      from esb2_trans_log t, servicesystem p
     where t.trans_date >=
           to_date('2019-08-30 00:00:00', 'yyyy-mm-dd hh24:mi:ss')
       and t.trans_date <=
           to_date('2019-08-30 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
       and t.logicchannel = p.name
       and t.flowstepid in ('4', 'E')
       and t.logicsystem = 'PICP') a
     group by  a.consumer,a.status
     order by 1 
    
    1 信贷系统 失败 4348
    2 信贷系统 成功 405
    3 小微地图 失败 1090
    4 小微地图 成功 156
    5 新柜面 失败 13852
    6 新柜面 成功 681
    7 直销银行 失败 1953
    8 直销银行 成功 138
    9 移动平台 失败 756
    10 移动平台 成功 42
    11 第三方支付平台 失败 2372
    12 第三方支付平台 成功 180
    13 网银系统 失败 1881
    14 网银系统 成功 5
    15 远程业务办理平台 失败 3598
    16 远程业务办理平台 成功 442
    17 金融云平台 失败 4726
    18 金融云平台 成功 329
    19 集中作业平台 失败 6387
    20 集中作业平台 成功 179
    
    转换成一行:
    select consumer,
           succes_count,
           err_count,
           round(succes_count / (succes_count + err_count) * 100, 2) || '%'
      from (select consumer,
                   replace(regexp_substr(str1, '[^######]+', 1, 1),
                           '成功---',
                           '') as succes_count,
                   replace(regexp_substr(str1, '[^######]+', 1, 2),
                           '失败---',
                           '') as err_count
            
              from (select consumer,
                           listagg(status || '---' || cnt || '######') within group(order by cnt) as str1
                      from (select a.consumer, a.status, count(*) as cnt
                              from (select /*+ parallel(t 8)*/
                                     p.description as consumer,
                                     case t.respcode
                                       when '000000' then
                                        '成功'
                                       when '01' then
                                        '成功'
                                       else
                                        '失败'
                                     end as status
                                      from esb2_trans_log t, servicesystem p
                                     where t.trans_date >=
                                           to_date('2019-08-30 00:00:00',
                                                   'yyyy-mm-dd hh24:mi:ss')
                                       and t.trans_date <=
                                           to_date('2019-08-30 23:59:59',
                                                   'yyyy-mm-dd hh24:mi:ss')
                                       and t.logicchannel = p.name
                                       and t.flowstepid in ('4', 'E')
                                       and t.logicsystem = 'PICP') a
                             group by a.consumer, a.status
                             order by 1) b
                     group by consumer)) d
    
    1 远程业务办理平台 442 3598 10.94%
    2 集中作业平台 179 6387 2.73%
    3 新柜面 681 13852 4.69%
    4 移动平台 42 756 5.26%
    5 直销银行 138 1953 6.6%
    6 第三方支付平台 180 2372 7.05%
    7 金融云平台 329 4726 6.51%
    8 信贷系统 405 4348 8.52%
    9 小微地图 156 1090 12.52%
    10 网银系统 5 1881 .27%
  • 相关阅读:
    c中%
    led,key通用IO的端口
    运行UART的程序
    大端和小段
    看门狗
    关于webpack的path和publicPath。
    转义BABEL的POLYFILL和RUNTIME的区别
    前端博客地址
    Webpack的使用指南-Webpack的常用解决方案
    webpack学习笔记
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348696.html
Copyright © 2011-2022 走看看