【发布时间】:2012-12-21 06:43:26
【问题描述】:
表 1:
id | typeid | available|
0 | 1 | 12 |
0 | 2 | 44 |
表 2:
typeid | typename |
1 | CL |
2 | ML |
我有一个使用concat 和group_concat 的查询:
select id,concat(group_concat(typename,available)) as types from table1
join table2 on table2.typeid=table1.typeid
我得到的结果是:
id | types |
0 | CL12,ML44 |
但我想这样显示:
id | CL | ML |
0 | 12 | 44 |
有没有办法将group_concat 结果拆分为列头?
我想从 table2 动态获取数据。一些用户可以将数据添加到 table2。所以硬编码类型名是不可能的。
【问题讨论】:
标签: mysql select pivot-table group-concat