mysql 多列转多行

id type name c1 c2 c3 c4 c5
1 2 3 0.1 0.2 0.3 0.4 0.5
2 3 4 0.3 0.4 0.9 0.8 0.6
表结构如此,需要显示为内容

id type name c_n
1 2 3 0.1
1 2 3 0.2

......

你可以这样

select id,type,name,c1 as c_n union
select id,type,name,c2 as c_n union
select id,type,name,c3 as c_n union
select id,type,name,c4 as c_n union
select id,type,name,c5 as c_n order by id;

看看行不

追问

嗯,union是可以的。但是这个会很麻烦,我的列会有很多。最好是批量转的。

追答

这好像你就得自己写程序操作了,SQL好像没有更好的方法了吧

追问

mysql貌似是没有,但是我必须要mysql来搞,真是纠结啊。

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答