我正在处理一个用例,在这个用例中,我需要在case语句中使用聚合.下面是相同的逻辑
If the column1 matches column2 then data else array_join(array_agg(data), ';')
以下是我的输入数据集-
column1 column2
de decore
uk ukcore
es escore
ca cacore
es escore
uk ukcore
ww a1sz
ww a1qu
ww a1pp
ww a1kv
ww a1ba
ww a15j
pl plcore
以下是我所需的输出
column1 column2
de decore
uk ukcore
es escore
ca cacore
es escore
uk ukcore
ww a1sz;a1qu;a1pp;a1kv;a1ba;a15j
pl plcore
我try 使用以下查询- Query1个
Select column2,
case
when trim(lower(split(column2,'xyz')[1])) = trim(lower(column1)) then column2 else array_join(array_agg(column2), ';') end as column2
from my_table
group by column2, column1
Query2个
Select column2,
case
when trim(lower(column1)) like CONCAT( '%', trim(lower(column2)), '%') then column2 else array_join(array_agg(column2), ';') end as column2
from my_table
group by column2, column1
但它们都没有奏效.请帮帮忙