zoukankan      html  css  js  c++  java
  • [转]Oracle 分组聚合二种写法,listagg和wmsys.wm_concat

    本文转自:http://www.cnblogs.com/ycdx2001/p/3502495.html

    复制代码
    with temp as(
    select 'China' nation ,'Guangzhou' city from dual union all
    select 'China' nation ,'Shanghai' city from dual union all
    select 'China' nation ,'Beijing' city from dual union all
    select 'USA' nation ,'New York' city from dual union all
    select 'USA' nation ,'Bostom' city from dual union all
    select 'Japan' nation ,'Tokyo' city from dual 
    )
    select nation,listagg(city,',') within GROUP (order by city)
    from temp
    group by nation
    复制代码
    select goodsid,listagg(ss.StorageNo,',')  within group (order by ss.StorageNo) StorageNo
          from StorageGoods ssg
          left join storage ss on ssg.storageid=ss.guid
          group by goodsid
    select goodsid,wmsys.wm_concat(ss.StorageNo) StorageNo
          from StorageGoods ssg
          left join storage ss on ssg.storageid=ss.guid
          --where ssg.goodsid=sd.goodsid
          group by goodsid

    oracle合并列的函数wm_concat的使用详解

    http://www.jb51.net/article/37604.htm

    oracle wm_concat(column)函数使我们经常会使用到的,下面就教您如何使用oracle wm_concat(column)函数实现字段合并,如果您对oracle wm_concat(column)函数使用方面感兴趣的话,不妨一看。
    shopping:
    -----------------------------------------
    u_id       goods            num
    ------------------------------------------
    1                苹果                2
    2                 梨子               5
    1                 西瓜               4
    3                 葡萄               1
    3                香蕉                1
    1               橘子                 3
    =======================
    想要的结果为:
    --------------------------------
    u_id          goods_sum
    ____________________
    1              苹果,西瓜,橘子
    2              梨子
    3              葡萄,香蕉
    ---------------------------------
    1.select u_id, wmsys.wm_concat(goods) goods_sum  2. 3.from shopping  4. 5.group by u_id 
    想要的结果2:
    --------------------------------
    u_id          goods_sum
    ____________________
    1              苹果(2斤),西瓜(4斤),橘子(3斤)
    2              梨子(5斤)
    3              葡萄(1斤),香蕉(1斤)
    ---------------------------------
    使用oracle wm_concat(column)函数实现:
    select u_id, wmsys.wm_concat(goods || '(' || num || '斤)' ) goods_sum 
    from shopping  
    group by u_id 
    mysql---group_concat

  • 相关阅读:
    Linux安装svn
    spring低版本报错:java.lang.IllegalStateException: Context namespace element ‘annotation-config’ and its parser class [*] are only available on
    linux下nproc的作用
    Oracle存储过程--案例
    Oracle存储过程
    LoadRunner 11 安装
    BZOJ 1061 志愿者招募(最小费用最大流)
    ZOJ 1015 Fishing Net(判断弦图)
    BZOJ 1049 数字序列(LIS)
    topcoder srm 620 div1
  • 原文地址:https://www.cnblogs.com/freeliver54/p/5726177.html
Copyright © 2011-2022 走看看