mysql中是否有一个函数可以返回一行中的所有项目?
示例:
Table:
| id | name |
-------------
| 1 | john |
| 2 | mike |
| 3 | jane |
查询:
SELECT concat_name(name) FROM tbl_name
concat_name
作为功能。
预期结果:
| name |
-------------------
| john, mike, jane|
答案 0 :(得分:4)
使用group_concat()
:
select group_concat(name order by id separator ',') as name
from table;
答案 1 :(得分:0)
使用GROUP_CONCAT
功能
http://dev.mysql.com/tech-resources/articles/4.1/grab-bag.html
SELEct m.meal_Id,
GROUP_CONCAT(dish_id) dish_ids,
GROUP_CONCAT(dish_name) dish_names
FROM DISH_HAS_DISHES m JOIN DISH d ON (m.dish_id = d.dish_id)
GROUP BY meal_Id