oracle将多行字段拼接成一个列 (listagg函数)

1、基本语法

将多行同列合并展示为一行:LISTAGG(展示字段,分隔符) WITHIN GROUP( ORDER BY 分组维度)

2、解析

复制代码
with temp as(
select '中国' country ,'北京' city from dual 
union all
select '中国' country ,'深圳' city from dual 
union all
select '中国' country ,'上海' city from dual 
)
select country,listagg(city,',') within GROUP (order by country) as brands
from temp
group by country
复制代码

 

 

 

 

 

 

posted @   Faith_zhang  阅读(3659)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
点击右上角即可分享
微信分享提示