如何只在一行中创建mysql答案

时间:2012-05-04 06:08:00

标签: mysql

  

可能重复:
  MySQL Results as comma separated list
  Combine Multiple child rows into one row MYSQL
  SQL query to pivot a column using CASE WHEN

enter image description here

我想这样做一个查询:

SELECT `name` AS `data` FROM `test_table` WHERE `level` = 1 ORDER BY `id`;

但我希望它只用一行','来回答我!像这样:

data = a,b,

不使用PHP,是否可以仅使用MySQL?怎么样?谢谢。

1 个答案:

答案 0 :(得分:4)

SELECT  GROUP_CONCAT(name ORDER BY id SEPARATOR ';')
FROM    test_table
WHERE   level = 1