由于2-天,我想找到一个解决方案...
SQL连接映射表,并取回列不列
我有两个表:
- 组件 - colums: ID |名称|说明
- components_ingredients - colums: component_id | ingredient_id
=>一个组件可以有多种成分
所以当我加入我的发言表:
SELECT * FROM组分c INNER JOIN components_ingredients CI ON c.id = ci.component_id
我为表ci中的每种成分找回一行。但是我想回到只有一行与匹配的成分作为额外的列,如:
c.id | c.name | c.description | ci.ingredient1 | ci.ingredient2 | ci.ingredient3 ...
这是可能的,何时?
感谢
你在找什么是PIVOT。类似的问题有多种答案。这里是一个:http://stackoverflow.com/questions/7674786/mysql-pivot-table – Kevin