[转]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
[转]Oracle 分组聚合二种写法,listagg和wmsys.wm_concat的更多相关文章
- Oracle 分组聚合二种写法,listagg和wmsys.wm_concat
with temp as( select 'China' nation ,'Guangzhou' city from dual union all select 'China' nation ,'Sh ...
- mysql中sql语句中常见的group_concat()函数意思以及用法,oracle中与其一样的功能函数是wmsys.wm_concat()
1.group_concat(),手册上说明:该函数返回带有来自一个组的连接的非NULL值的字符串结果.比较抽象,难以理解. 通俗点理解,其实是这样的:group_concat()会计算哪些行属于同一 ...
- oracle中listagg()和wmsys.wm_concat()基本用法
一.LISTAGG() 简介 介绍:其函数在Oracle 11g 版本中推出,对分组后的数据按照一定的排序进行字符串连接. 其中,“[,]”表示字符串连接的分隔符,如果选择使用[over (parti ...
- oracle 循环的一种写法
for v_n in( select bb.temNum, bb.LOANTYPE from (select decode(bns.assignstate, '{016D68F9-719B-4EFC- ...
- Oracle数据库sql 列转字符串行函数WMSYS.WM_CONCAT()
例.select TO_CHAR(WMSYS.WM_CONCAT(ID)) from patrol_data_content where patrol_unit_id = '1628D189543B ...
- ORACLE字符串分组聚合函数(字符串连接聚合函数)
ORACLE字符串连接分组串聚函数 wmsys.wm_concat SQL代码: select grp, wmsys.wm_concat(str) grp, 'a1' str from dual un ...
- oracle if/else功能的实现的3种写法
转载:oracle中if/else功能的实现的3种写法 以下是内容留存: 1.标准sql规范 一.单个IF . if a=... then ......... end if; . if a=... t ...
- ORACLE 查询一个数据表后通过遍历再插入另一个表中的两种写法
ORACLE 查询一个数据表后通过遍历再插入另一个表中的两种写法 语法 第一种: 通过使用Oracle语句块 --指定文档所有部门都能查看 declare cursor TABLE_DEPT and ...
- 事件处理之二:点击事件监听器的五种写法 分类: H1_ANDROID 2013-09-11 10:32 4262人阅读 评论(1) 收藏
首选方法二! 方法一:写一个内部类,在类中实现点击事件 1.在父类中调用点击事件 bt_dail.setOnClickListener(new MyButtonListener()); 2.创建内部类 ...
随机推荐
- Matter.js – 你不能错过的 2D 物理引擎
Matter.js 是一个 JavaScript 2D 刚体物理引擎的网页.Matter.Engine 模块包含用于创建和操作引擎的方法.这个引擎是一个管理更新和渲染世界的模拟控制器. Matter. ...
- 【初探移动前端开发05】jQuery Mobile (下)
前言 继续我们移动端的学习,今天到了List相关了. 本文例子请使用手机查看 List列表 在移动设备平台下,由于移动设备屏幕比较小,我们又是用手在上面点击的触屏方式,传统的列表模式在手机上就不太友好 ...
- 从0开始学angularjs-笔记01
一.angularjs简介 AngularJS 是一个为动态WEB应用设计的结构框架.它能让你使用HTML作为模板语言,通过扩展HTML的语法,让你能更清楚.简洁地构建你的应用组件.它的创新点在于,利 ...
- [deviceone开发]-do_Dialog的基本使用示例
一.简介 我们平常使用do_Notification的alert或者confirm都是比较简单弹窗. 更为复杂和个性化的弹窗需要用到do_Dialog, 它可以弹出一个自定义的窗口,窗口里的内容是你自 ...
- windows.open()、close()方法详解
windows.open()方法详解: window.open(URL,name,features,replace)用于载入指定的URL到新的或已存在的窗口中,并返回代表新窗口的Win ...
- xmpp整理笔记:用户网络连接及好友的管理
xmpp中的用户连接模块包括用户的上线与下线信息展现,用户登录,用户的注册: 好友模块包括好友的添加,好友的删除,好友列表的展示. 在xmpp中 负责数据传输的类是xmppStream,开发的过程中, ...
- NSURLSession从网络上下载资源,此程序下载的是视频
#import "ViewController.h" @interface ViewController ()<NSURLSessionDelegate, NSURLSess ...
- Android-SQLite版本问题
1. 用户 重来没有使用过该软件 不存在数据库,我们 1). 自动调用 void onCreate(SQLiteDatabase db) 方法 创建数据库 2).创建 表 , 3).给表插入初始化数据 ...
- 【C语言】C语言数据类型
目录: [数据类型图] [基本数据类型] · 整型 · 实型 · 字符型 · 布尔类型 1.数据类型图 2.基本数据类型 · 整型 用于准确表示整数,根据表示范围的不同分为三种:短整型 ...
- ios 颜色转图片
- (UIImage *)imageWithColor:(UIColor*) color{ CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); ...