我在雪花中有这个
我想把它变成这样
我尝试写这个,但似乎是错误的
df_alerts_3 = df_alerts_2.groupBy('id_request')\
.agg(concat_ws(lit(','), array_agg('alert_code')).alias('alert_all'))
非常感谢您的帮助
最佳答案
CONCAT_WS在单行上下文中连接字符串。要跨多行连接字符串,您需要使用聚合函数 LISTAGG .
Snowpark 等效项是 snowflake.snowpark.functions.listagg :
Returns the concatenated input values, separated by delimiter string
df.group_by(df.col1).agg(listagg(df.col2. ",")).within_group(df.col2.asc()) df.select(listagg(df["col2"], ",", False)
关于python - 雪花Snowpark Python : Group By and Concat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75680447/