zoukankan      html  css  js  c++  java
  • Oracle列转行函数LISTAGG()

    --Oracle列转行函数LISTAGG()
    with tb_temp as(
      select 'China' 国家,'Wuhan' 城市 from dual union all
      select 'China' 国家,'Dongjing' 城市 from dual union all
      select 'China' 国家,'Xijing' 城市 from dual union all
      select 'Germany' 国家,'Berlin' 城市 from dual union all
      select 'USA' 国家,'NewYork' 城市 from dual union all
      select 'USA' 国家,'Washington' 城市 from dual
    )
    select 国家,listagg(城市,',') within group(order by 城市) as 一些城市
    from tb_temp 
    group by 国家
    
    --不使用Group by语句时候,也可以使用LISTAGG函数:
    with temp 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 population,  
    nation,  
    city,  
    listagg(city,',') within GROUP (order by city) over (partition by nation) rank  
    from temp
  • 相关阅读:
    IOS第一天
    Mac环境下svn的使用
    惯用代码
    ORA-12170: TNS: 连接超时
    java字符集
    java移位运算
    mysql面试题
    mysql覆盖索引(屌的狠,提高速度)
    Cannot call sendError() after the response has been committed
    maven生命周期
  • 原文地址:https://www.cnblogs.com/niwotaxuexiba/p/9997727.html
Copyright © 2011-2022 走看看