You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Error Code:1305报错:FUNCTION string_agg不存在,求解决方案

解决MySQL中string_agg不存在的报错(Error Code:1305)

string_agg是PostgreSQL等数据库的字符串聚合函数,MySQL并不支持该函数,这是报错的核心原因。你需要替换为MySQL原生支持的GROUP_CONCAT()函数来实现相同的字符串聚合效果。

修改后的完整SQL代码如下:

select customer_id, budget, count(*) as no_of_product, GROUP_CONCAT(p.product_id) as list_of_product 
FROM customer_budget c
left join 
(SELECT *, sum(cost) over (order by cost) as r_cost FROM product) p
on c.budget>=p.r_cost 
group by customer_id, budget;

额外说明

如果需要自定义聚合后的字符串分隔符,可以通过SEPARATOR参数指定,例如用分号分隔:

GROUP_CONCAT(p.product_id SEPARATOR ';')

内容的提问来源于stack exchange,提问作者Sk337

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 07:36:19