SQL group by和listing

时间:2015-12-23 11:09:46

标签: sql list group-by

我在DB中有以下信息:

id | name     | company
---+----------+------
 1 | Joe      | company_1
 2 | Sally    | company_2
 3 | Marc     | company_3
 4 | Bob      | company_1

可以在SQL中执行类似的操作:

SELECT company, _something_ FROM my_db GROUP BY company

得到:

 company   | members
---------- | ---------
 company_1 | Joe, Bob
 company_2 | Sally
 company_3 | Marc

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

<强> MySQL的:

SELECT company, GROUP_CONCAT(name SEPARATOR ',') AS members FROM my_table GROUP BY company