MySQL - 将列拆分为多列 [英] MySQL - Split the column in multiple columns
问题描述
如何将列拆分为多个列,以便每列包含不同ID的值?
选择 ID,值来自 table1
ID价值
==========
1 test1
1 test2
2 test3
2 test4
2 test5
2 test6
我希望结果集基于ID列分成多个部分。每个ID需要有不同的栏目
ID ID值ID
=============== ===========
1 test1 2 test3
1 test2 2 test4
2 test5
2 test6
您是否只使用MySQL?
有一些简单的选项,例如:
创建 表 new 选择 id,值来自 table1 其中 id = 1 跨度>;
How can I split a column into multiple columns so that each column contain the values for different ID?
select ID, Value from table1
ID Value
==========
1 test1
1 test2
2 test3
2 test4
2 test5
2 test6
I want the resultset split in multiple parts based on the ID column. Each ID need to have different column
ID Value ID Value
==========================
1 test1 2 test3
1 test2 2 test4
2 test5
2 test6
Are you using MySQL only?
There some easy options, for example:
create table new select id,value from table1 where id = 1;
这篇关于MySQL - 将列拆分为多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!