1

我有一个 MySQL 数据库:

-------------------------------------------------------------------
Email                 | Name                      | Tag
-------------------------------------------------------------------
test@test.com         |Test Person               | TagOne
test@test.com         |Test Person               | Tag Two
-------------------------------------------------------------------

需要一个将返回的 SQL 查询

-------------------------------------------------------------------
Email                 | Name                      | Tag
-------------------------------------------------------------------
test@test.com         |Test Person               | TagOne, Tag Two
-------------------------------------------------------------------

我怎样才能做到这一点?

4

2 回答 2

3

利用:

  SELECT t.email,
         t.name,
         GROUP_CONCAT(DISTINCT t.tag ORDER BY t.tag SEPARATOR ', ')
    FROM YOUR_TABLE t
GROUP BY t.email, t.name

参考:

于 2010-05-16T21:04:43.843 回答
0

对于其他试图这样做并被卡住的人:

SELECT Email, Name, GROUP_CONCAT(Tag ORDER BY Tag ASC SEPARATOR ', ')
FROM Table
GROUP BY Email
于 2010-05-16T21:07:17.330 回答