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
  • 相关阅读:
    字符串复习笔记
    构造
    网络流复习笔记
    LCT学习笔记
    省选前的数据结构训练
    在windows安装并启动测试kafka
    Scala 原生操作MySQL
    Scala基础语法
    ORACLE查出表所有的触发器及触发器详细信息
    转载二,JAVA面试题
  • 原文地址:https://www.cnblogs.com/niwotaxuexiba/p/9997727.html
Copyright © 2011-2022 走看看