从众多行到唯一行的字符串字段聚合

String field aggregation from numerous lines to unique line

例如,我可以这样 table :

我想使用 HQL 对我的 ID 进行分组并汇总我的数据。结果可能是:

有像 count 或 avg 这样的运算符来聚合这样的字符串吗?

感谢您的帮助

您可以使用 collect_list to keep the duplicate data intact or use collect_set 删除重复值。

select id,collect_list(data)
from tbl
group by id

使用 collect_list() 将字符串聚合到数组中 + concat_ws(delimiter, array<string>) 用于连接数组以获得分隔字符串:

select id, 
       concat_ws(' ',collect_list(data)) as aggregated_data
  from tbl
 group by id;