Table 1:
id | typeid | available|
0 | 1 | 12 |
0 | 2 | 44 |
Table 2:
typeid | typename |
1 | CL |
2 | ML |
I have a query using concat
and group_concat
:
select id,concat(group_concat(typename,available)) as types from table1
join table2 on table2.typeid=table1.typeid
I got the result as:
id | types |
0 | CL12,ML44 |
But I want to display it like this:
id | CL | ML |
0 | 12 | 44 |
Is there any way to split the group_concat
result to columns heads?
I want dynamically fetch data from table2. Some user can add data to table2. So hard-coding typename is not possible.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…