listagg多行合并为一行
listagg有两种用法:
1、分析函数,如: row_number()、rank()、dense_rank() 等,用法相似 listagg(合并字段, 连接符) within group(order by 合并的字段的排序) over(partition by 分组字段)
2、聚合函数,如:sum()、count()、avg()等,用法相似 listagg(合并字段, 连接符) within group(order by 合并字段排序) --后面跟 group by 语句
示例:
1、聚合函数
列出家住一个地方的人员
select * from STUDENTS_INFORMATION;
select S_ADDER, listagg(S_NAME, ',') within group ( order by S_ID)
from STUDENTS_INFORMATION
group by S_ADDER;
2、分析函数示例
select s_id,
s_name,
s_id_no,
s_adder,
s_sex,
s_brithday,
listagg(S_NAME, ',') within group ( order by S_ID) over ( partition by S_ADDER)
from STUDENTS_INFORMATION;
本文链接:
/archives/listagg
版权声明:
本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自
ZFS的成长之路!
喜欢就支持一下吧