如何在mysql中连接此脚本中的列?

tag5nh1u  于 2021-08-13  发布在  Java
关注(0)|答案(1)|浏览(237)

下面是一个sql查询,我正在使用它连接sql server中的列。如何在mysql中连接相同的内容?

SELECT Name, STRING_AGG(school,',') AS School
,STRING_AGG(class,',') AS Class
,STRING_AGG(description,',') AS Description
,MIN(start_date) AS Start_date
,MAX(end_date) AS End_date FROM source_table GROUP BY Name
3bygqnnd

3bygqnnd1#

mysql中的等效函数是 group_concat() :

SELECT Name, GROUP_CONCAT(school) AS Schools,
       GROUP_CONCAT(class) AS Classes,
       GROUP_CONCAT(description) AS Descriptions,
       MIN(start_date) AS Start_date,
       MAX(end_date) AS End_date
FROM source_table
GROUP BY Name;

默认的分隔符是逗号,因此不需要显式提供它。

相关问题