查询会在一列中分解多个值

时间:2013-07-12 16:15:46

标签: mysql sql

我需要你的帮助。我有2张桌子。

1.company_classifications

company_name-classifications

Company A-1,2,3

Company B-1,2

2.classifications

id-name

1-Music 

2-Technologi

3-Food

我需要查询结果如下:

company_name-classification_name

Company A-Music, Technologi, Food   

Company B-Music, Food

1 个答案:

答案 0 :(得分:0)

select cc.company_name,group_concat(c.name)
from company_classifications cc 
inner join classifications c 
on c.id = find_in_set(c.id,cc.classifications)
group by cc.company_name;

fiddle