• [转]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

  • 相关阅读:
    Android Things专题 1.前世今生
    用Power BI解读幸福星球指数
    [leetcode]Simplify Path
    字段的划分完整的问题
    k-means算法MATLAB和opencv代码
    【Oracle】RAC下的一些经常使用命令(一)
    Java中经常使用缓存Cache机制的实现
    jenkins环境自动部署
    jenkins环境搭建
    springboot单元测试@test的使用
  • 原文地址:https://www.cnblogs.com/freeliver54/p/5726177.html
Copyright © 2020-2023  润新知