码迷,mamicode.com
首页 > 数据库 > 详细

oracle分析函数listagg

时间:2020-01-14 20:53:54      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:from   分析   tno   create   char   union   ble   rac   group   

drop table t_thz_listagg;
create table t_thz_listagg(
n_id number(8),
s_name varchar2(100),
n_deptno number(8)
);
insert into t_thz_listagg(n_id,s_name,n_deptno)
select 1 ,‘麦片‘,20 from dual
union all
select 2 ,‘西瓜‘,30 from dual
union all
select 3 ,‘芝麻糊‘,20 from dual
union all
select 4 ,‘保温杯‘,10 from dual
union all
select 5 ,‘哈密瓜‘,30 from dual
union all
select 6 ,‘燕麦‘,20 from dual
union all
select 7 ,‘‘,40 from dual
union all
select 8 ,‘‘,40 from dual
;
commit;
select * from t_thz_listagg;

--分组

select n_deptno
,listagg(s_name,‘,‘) within group (order by n_id) as str
from t_thz_listagg
group by n_deptno;

--不分组

select t.*,listagg(s_name,‘,‘) within group (order by n_id) over (partition by n_deptno) from t_thz_listagg t;

oracle分析函数listagg

标签:from   分析   tno   create   char   union   ble   rac   group   

原文地址:https://www.cnblogs.com/jiangqingfeng/p/12193688.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!