• 【SQL查询】合并行_listagg


    listagg

    1. 语法:

      listagg(measure_expr, 'delimiter') within group (order by expr) [over (partition by expr)]

    2. 功能说明:

      measure_expr:任何基于列的表达式

      delimiter:分割符

      order by expr:决定被拼接的顺序

      over (partition by expr): 表中所有内容按照expr进行分区处理

    3. 【示例1】:

    create or replace view v as(  
      select 500 population, 'China' nation ,'Guangzhou' city from dual union all  
      select 1500 population, 'China' nation ,'Shanghai' city from dual union all  
      select 500 population, 'China' nation ,'Beijing' city from dual union all  
      select 1000 population, 'USA' nation ,'New York' city from dual union all  
      select 500 population, 'USA' nation ,'Bostom' city from dual union all  
      select 500 population, 'Japan' nation ,'Tokyo' city from dual   
    );  
    
    select v.population, v.nation, listagg(v.city, ',') within group (order by city) over (partition by nation) as rank from v;

      结果:

      

      【示例2】:

      

    create or replace view v as(  
      select 500 population, 'China' nation ,'Guangzhou' city from dual union all  
      select 1500 population, 'China' nation ,'Shanghai' city from dual union all  
      select 500 population, 'China' nation ,'Beijing' city from dual union all  
      select 1000 population, 'USA' nation ,'New York' city from dual union all  
      select 500 population, 'USA' nation ,'Bostom' city from dual union all  
      select 500 population, 'Japan' nation ,'Tokyo' city from dual   
    );  
    
    select v.nation, listagg(v.city, ',') within group (order by city) as rank from v group by nation;

    :listagg在这里启动汇总的作用。sum将数值结果加在一起,而listagg是把字符串连接在一起。

     

  • 相关阅读:
    TODO: Android UI测试 UIAutomator
    Android-jacoco代码覆盖率:单元测试覆盖率+功能测试覆盖率
    Android --其他测试点
    Android 测试-Robolectric,mockito,esspresso
    Android adb的一些用法
    Android上执行python脚本-QPython
    【洛谷P1080】国王游戏
    【洛谷P2123】皇后游戏
    【洛谷P2340】 奶牛会展
    【洛谷P1982】小朋友的数字
  • 原文地址:https://www.cnblogs.com/zhuhaiying/p/12218517.html
Copyright © 2020-2023  润新知