场景
将账户表中同一个用户的账户号合并显示在一条记录中
select name, listagg(account_name, ',') within group(order by name) from user_account group by name;
建表sql语句
create table user_account( id number(12,0) primary key, name varchar(50), account_name varchar(50), balance number(10,2) ); insert into user_account values(1, 'wangwu', 'wangwuAccount1', 600); insert into user_account values(2, 'wangwu', 'wangwuAccount2', 400); insert into user_account values(3, 'lisi', 'lisiAccount1', 200); insert into user_account values(4, 'lisi', 'lisiAccount2', 1000); insert into user_account values(5, 'zhangsan', 'zhangsanAccount1', 500); insert into user_account values(6, 'zhangsan', 'zhangsanAccount2', 500); insert into user_account values(7, 'zhangsan', 'zhangsanAccount3', 500);
查询sql语句
一般查询:
select * from user_account order by id
结果:
将account_name字段根据name字段进行合并
select name, listagg(account_name, ',') within group(order by name) from user_account group by name;
结果:
---------------------
参考链接:https://blog.csdn.net/qq_36743920/article/details/80291166
- 本文固定链接: https://www.coordsoft.com/post/29.html
- 转载请注明: admin 于 生活随想 - zwgu 's world 发表
《本文》有 0 条评论