我的當前查詢: -CONCAT字符串明智
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的順序...爲了看到 - > http://stackoverflow.com/questions/995373/mysql-sort-group-concat值 – xQbert