【发布时间】:2012-01-19 07:13:21
【问题描述】:
我当前的查询:-
select
p.id as product_id,
p.product_name,
child.name as category_name,
parent.name as parent_category_name
from category child
left join products p on FIND_IN_SET(child.id,p.category_ids)
left join category parent on parent.id = child.parentid and parent.parentid = 0
where p.id = 7
当前结果:-
product_Id | product_name | category_name | parent_category_name
7 ponds cream chemical
7 ponds medicine chemical
7 ponds powder Ayurvedic
现在我想按产品 ID 进行分组,并且子/父类别应以逗号分隔的格式显示,例如“奶油、药物、粉末”。所以这里的记录数只有这样一个:-
预期结果:-
product_Id | product_name | category_name | parent_category_name
7 ponds cream,medicine,powder chemical,chemical,Ayurvedic
我不知道它是否可能在 mysql 查询中。
任何建议或想法将不胜感激。
非常感谢。
【问题讨论】:
-
只要你不关心组 concat 中的顺序...看-->stackoverflow.com/questions/995373/…
标签: mysql join left-join concat