此问题在此处已有答案:
LISTAGG in Oracle to return distinct values(24回答)
22天前关闭
我有一个表格,数据如下:
emp_id company_id company_version_id account_id duplicate_account_id
174043265 10622557 1 201013278 101104723
174043265 10622557 1 201013278 200999888
174043265 10622557 1 201013278 203010306
174043265 10622557 1 201013278 205436979
174043265 10622557 1 201013278 205436980
174043265 10622557 1 201013293 101104723
174043265 10622557 1 201013293 200999888
174043265 10622557 1 201013293 203010306
174043265 10622557 1 201013293 205436979
174043265 10622557 1 201013293 205436980
字符串
在Oracle中,如何实现以下功能:
emp_id company_id company_version_id account_id duplicate_account_id
174043265 10622557 1 201013278, 201013293 101104723, 200999888, 203010306, 205436979, 205436980
型
x1c 0d1x的数据
创建表并测试的代码:
create table dummy_data AS
select 174043265 emp_id, 10622557 company_id, 1 company_version_id, 201013278 account_id, 101104723 duplicate_account_id from dual union all
select 174043265 emp_id, 10622557 company_id, 1 company_version_id, 201013278 account_id, 200999888 duplicate_account_id from dual union all
select 174043265 emp_id, 10622557 company_id, 1 company_version_id, 201013278 account_id, 203010306 duplicate_account_id from dual union all
select 174043265 emp_id, 10622557 company_id, 1 company_version_id, 201013278 account_id, 205436979 duplicate_account_id from dual union all
select 174043265 emp_id, 10622557 company_id, 1 company_version_id, 201013278 account_id, 205436980 duplicate_account_id from dual union all
select 174043265 emp_id, 10622557 company_id, 1 company_version_id, 201013293 account_id, 101104723 duplicate_account_id from dual union all
select 174043265 emp_id, 10622557 company_id, 1 company_version_id, 201013293 account_id, 200999888 duplicate_account_id from dual union all
select 174043265 emp_id, 10622557 company_id, 1 company_version_id, 201013293 account_id, 203010306 duplicate_account_id from dual union all
select 174043265 emp_id, 10622557 company_id, 1 company_version_id, 201013293 account_id, 205436979 duplicate_account_id from dual union all
select 174043265 emp_id, 10622557 company_id, 1 company_version_id, 201013293 account_id, 205436980 duplicate_account_id from dual
型
如果listagg长度限制也被处理(没有截断),那就太好了。
- 谢谢-谢谢
1条答案
按热度按时间1mrurvl11#
说你使用Oracle是不够的-它是哪个版本?因为,
listagg
在最近的版本中支持distinct
:字符串
如果你的数据库不支持它,首先找到不同的值,然后聚合它们:
型