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
  • 相关阅读:
    mssql like的效率
    【编辑器开发】基本js指令
    QQ菜单OUTLOOK风格
    oracle exp/imp命令详解
    javascript读取xml
    在c#中调用windows脚本的方法
    oracle常用命令(转)
    有效创建Oracle dblink的两种方式
    oracle 绑定变量(bind variable)
    Oracle备份与恢复
  • 原文地址:https://www.cnblogs.com/niwotaxuexiba/p/9997727.html
Copyright © 2011-2022 走看看