oracle listagg函数讲讲

[复制链接]
发表于 2024-6-14 22:02:12 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
listagg是oracle11.2增加的特性。
功能雷同wmsys.wm_concat函数,即将数据分组后,把指定列的数据通过指定符号合并。
--listagg()函数,列转行。 在每个分组内,LISTAGG根据order by子句对列值举行排序,将排序后的结果拼接起来。
--根本语法;listagg(待处理列,毗连符号) within group(order by 用于拼接组内排序字段)
select a.* from test_userinfo a;
--分组函数:
select a.user_sex,listagg(a.user_school,',') within group(order by a.user_age) from test_userinfo a group by a.user_sex;
--分析函数:根据年岁分区,在分区内部拼接学校,然后拼接时按照性别排序
select a.user_name,a.user_age,a.user_school,listagg(a.user_school,',') within group(order by a.user_sex) over (partition by a.user_age) from test_userinfo a;




免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表