本文转自: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

[转]Oracle 分组聚合二种写法,listagg和wmsys.wm_concat的更多相关文章

  1. Oracle 分组聚合二种写法,listagg和wmsys.wm_concat

    with temp as( select 'China' nation ,'Guangzhou' city from dual union all select 'China' nation ,'Sh ...

  2. mysql中sql语句中常见的group_concat()函数意思以及用法,oracle中与其一样的功能函数是wmsys.wm_concat()

    1.group_concat(),手册上说明:该函数返回带有来自一个组的连接的非NULL值的字符串结果.比较抽象,难以理解. 通俗点理解,其实是这样的:group_concat()会计算哪些行属于同一 ...

  3. oracle中listagg()和wmsys.wm_concat()基本用法

    一.LISTAGG() 简介 介绍:其函数在Oracle 11g 版本中推出,对分组后的数据按照一定的排序进行字符串连接. 其中,“[,]”表示字符串连接的分隔符,如果选择使用[over (parti ...

  4. oracle 循环的一种写法

    for v_n in( select bb.temNum, bb.LOANTYPE from (select decode(bns.assignstate, '{016D68F9-719B-4EFC- ...

  5. Oracle数据库sql 列转字符串行函数WMSYS.WM_CONCAT()

    例.select TO_CHAR(WMSYS.WM_CONCAT(ID)) from patrol_data_content  where patrol_unit_id = '1628D189543B ...

  6. ORACLE字符串分组聚合函数(字符串连接聚合函数)

    ORACLE字符串连接分组串聚函数 wmsys.wm_concat SQL代码: select grp, wmsys.wm_concat(str) grp, 'a1' str from dual un ...

  7. oracle if/else功能的实现的3种写法

    转载:oracle中if/else功能的实现的3种写法 以下是内容留存: 1.标准sql规范 一.单个IF . if a=... then ......... end if; . if a=... t ...

  8. ORACLE 查询一个数据表后通过遍历再插入另一个表中的两种写法

    ORACLE 查询一个数据表后通过遍历再插入另一个表中的两种写法 语法 第一种: 通过使用Oracle语句块  --指定文档所有部门都能查看 declare cursor TABLE_DEPT and ...

  9. 事件处理之二:点击事件监听器的五种写法 分类: H1_ANDROID 2013-09-11 10:32 4262人阅读 评论(1) 收藏

    首选方法二! 方法一:写一个内部类,在类中实现点击事件 1.在父类中调用点击事件 bt_dail.setOnClickListener(new MyButtonListener()); 2.创建内部类 ...

随机推荐

  1. canvas粒子效果-snow

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. jQuery+fullPage.js演示10种全屏滚动

    基本演示 背景演示 循环演示 回调函数演示 绑定菜单演示 项目导航演示 自动滚动 slide自动滚动 响应式 下载地址 实例代码 <!DOCTYPE html> <html lang ...

  3. php 过滤英文标点符号 过滤中文标点符号

    php 过滤英文标点符号 过滤中文标点符号 代码 function filter_mark($text){ if(trim($text)=='')return ''; $text=preg_repla ...

  4. div水平居中

    1.先给它外层的div定位并left:position:absolute;left:50%; 2.获取当前元素div的宽度,并除以2 3.改变它的css:margin-left:-(获取当前元素div ...

  5. 送给我的朋友——Cry on my shoulder

    If the hero never comes to you如果你的真命天子仍未来到 If you need someone you"re feeling blue如果你情绪低落需要有人陪伴 ...

  6. GDAL关于读写图像的简明总结

    读写影像可以说是图像处理最基础的一步.关于使用GDAL读写影像,平时也在网上查了很多资料,就想结合自己的使用心得,做做简单的总结. 在这里写一个例子:裁剪lena图像的某部分内容,将其放入到新创建的. ...

  7. atitit.数据验证--db数据库数据验证约束

    atitit.数据验证--db数据库数据验证约束 1. 为了加强账户数据金额的安全性,需要增加验证字段..1 2. 创建帐户1 3. 更改账户2 4. ---code3 5. --fini4 1. 为 ...

  8. Android Action Bar简介

    Android Action Bar简介 Design: Action Bar Action Bar是在屏幕顶端的一部分内容,通常在整个app进行中都保持存在. 它提供了几个关键的功能: 1.使得重要 ...

  9. C语言中的函数与指针

    1. 为什么需要函数? 函数就是功能的封装. 函数就是为了实现某个功能而编写的一段代码 scanf()    ,  printf() 2.函数优点: 代码更简洁 代码复用 如果业务逻辑变化,只把相应的 ...

  10. [转 载] android 谷歌 新控件(约束控件 )ConstraintLayout 扁平化布局

    序 在Google IO大会中不仅仅带来了Android Studio 2.2预览版,同时带给我们一个依赖约束的库. 简单来说,她是相对布局的升级版本,但是区别与相对布局更加强调约束.何为约束,即控件 ...