如何在 MySql 中的 SQL 查询中将行折叠成逗号分隔的列表

问题描述:

在 T-SQL 中,在 SQL 查询中将相关值连接成逗号分隔的字符串相对简单(请参阅此处:将 SELECT 的行折叠为字符串的最佳方法是什么? 在这里:什么是将 SELECT 的行折叠为字符串的最佳方法?).后一个链接准确地描述了我需要做什么,但我需要在 MySql 中进行,而在 T-SQL 中工作的查询在 MySql 中不起作用.任何 MySql 专家都知道如何做到这一点?

It is relatively simple in T-SQL to concatenate related values into a comma delimited string in an SQL Query (see here: What is the best way to collapse the rows of a SELECT into a string? and here: What is the best way to collapse the rows of a SELECT into a string?). The latter link describes exactly what I need to do, but I need to do it in MySql, and the query that works in T-SQL doesn't work in MySql. Any MySql experts out there know how to do this?

谢谢!

被称为group_concat

select group_concat(your_id) from your_table