我有三张桌子如下
manufacturing_detail_history有两列主键,描述
manufacturing_products_history有两列primarykey和manu_product_id(主键是manufacturing_detail_history primarky键引用)
manufacturing_products有三列manu_product_id,name,type
需要在manufacturing_detail_history中添加新列manu_product_names,并使用逗号分隔值填充制造产品名称。
不确定如何为每个manu_product_id获取关联的多个manu_product_name并使其以逗号分隔值并插入manu_product_names列
提前致谢。
答案 0 :(得分:0)
Select
T1.ID, T1.Desc,
T2.manu_product_id,
GROUP_CONCAT(T3.name ORDER BY T3.name ASC SEPARATOR ',')
From
manufacturing_detail_history AS T1
inner join
manufacturing_products_history AS T2 ON T1.ID = T2.ID
inner join
manufacturing_products AS T3 ON T3.manu_product_id = T2.manu_product_id
GROUP BY T1.ID, T1.Desc, T2.manu_product_id;