在这样的查询中:
SELECT *
FROM `Keywords`
WHERE `Page` = 'food'
我的结果显示如下:
| Page | Keyword |
--------------------
| food | Pizza |
--------------------
| food | Burger |
--------------------
| food | Sushi |
--------------------
如何编写我的SQL语句,以获得类似这样的结果?:
| Page | Keyword |
-------------------------------
| food | Pizza, Burger, Sushi |
-------------------------------
最佳答案
SELECT `Page`, GROUP_CONCAT(`Keyword` SEPARATOR ', ') AS 'foods'
FROM `Keywords`
WHERE `Page` = 'food'
GROUP BY `Page`;
关于mysql - MySQL:在一行中选择多个记录,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25213871/