可能重复:
MySQL Results as comma separated list
Combine Multiple child rows into one row MYSQL
SQL query to pivot a column using CASE WHEN
我想这样做一个查询:
SELECT `name` AS `data` FROM `test_table` WHERE `level` = 1 ORDER BY `id`;
但我希望它只用一行',
'来回答我!像这样:
data = a,b,
不使用PHP,是否可以仅使用MySQL?怎么样?谢谢。
答案 0 :(得分:4)
SELECT GROUP_CONCAT(name ORDER BY id SEPARATOR ';')
FROM test_table
WHERE level = 1