如何连接 MySQL 中的字符串值

How to concatenate values of a string in MySQL

我正在尝试连接 MySQL 数据库中的值列值,但出现错误

FUNCTION sales.STRING_AGG does not exist

SELECT
    city, 
    STRING_AGG(email,';') email_list
FROM
    sales.customers
GROUP BY
    city;

我错过了什么?

你是说吗?

SELECT city, 
       GROUP_CONCAT(email) email_list 
FROM sales.customers 
GROUP BY city;

您需要使用group_concat

SELECT  city, 
        group_concat(email) email_list
FROM customers
GROUP BY city;

DEMO

您也可以在 group_concat() 函数内部排序,如下所示:

group_concat(email order by email) email_list

或将分隔符从默认 , 更改为 ;

group_concat(email order by email desc separator ';') email_list