presto array_join函数

本文介绍了array_join函数的作用,即用分隔符将数组元素组合成字符串,通过实例展示了如何使用它将正则表达式提取的数组合并为逗号分隔的字符串。重点在于函数的实际操作和应用场景演示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用途就是把array中的每个元素用分隔符连接起来

array_join(x, delimiter, null_replacement)varchar
Concatenates the elements of the given array using the delimiter and an optional string to replace nulls.

案例
如下regexp_extract_all提取字符串,返回值为array,之后用,把 array中的元素连接起来

> select array_join(regexp_extract_all('1a 2b 14m', '\d+'),',', 'none');
 _col0
--------
 1,2,14

总结

  • array_join就是把数组中的元素用特定分隔符连接成字符串
Presto中,可以使用array_agg函数将多个值转换为数组,使用array_distinct函数去除数组中的重复值,使用array_join函数将数组中的元素用逗号连接成字符串。下面是一个示例查询语句: ```sql SELECT user_id, array_join(array_distinct(array_agg(order_id)), ',') as order_ids FROM test.tmp_row_to_col GROUP BY user_id; ``` 这个查询会将test.tmp_row_to_col表中的数据按照user_id进行分组,然后将每个分组中的order_id聚合成一个数组,并去除数组中的重复值,最后将数组中的元素用逗号连接成字符串,并将结果作为order_ids列返回。 引用\[1\]是一个示例查询语句,展示了如何使用Presto的语法来实现行转列的功能。引用\[3\]是查询的最终结果,展示了每个user_id对应的order_ids。 请注意,这个查询语句是基于Presto的语法,如果你使用的是其他数据库,可能需要根据具体的数据库语法进行相应的调整。 #### 引用[.reference_title] - *1* *3* [【presto】行转列和列转行](https://blog.csdn.net/lz6363/article/details/124557442)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Hive/Spark/Presto/标准SQL实现行转列和列转行](https://blog.csdn.net/soaring0121/article/details/99870447)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

鸭梨山大哎

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值