我在Vertica上有一个专栏,它将数字存储为逗号连接的值字符串,例如:12,15,17
,例如:
ID | values
----------------------
A | 1,3,5
A | 2,3,5,6
B | 1,2,3
我想把这作为我的最终结果:
ID | values
----------------------
A | 1,2,3,5,6
B | 1,2,3
意思是,每个ID都包含所有不同的值。我该怎么做呢? (使用Vertica 8.1.1)
答案 0 :(得分:0)
找到它: 假设您知道每个条目的最大值是多少(在本例中假设为6):
with m as (
select 1 as i union all
select 2 as i union all
select 3 as i union all
select 4 as i union all
select 5 as i union all
select 6 as i),
splitted_data as (
select distinct ID, split_part('values',',',i) as value
from main_table cross join m)
select ID, rtrim(agg_concatenate(value||','),',') as values
from splitted_data