MySQL - 将列拆分为多列 [英] MySQL - Split the column in multiple columns

查看:102
本文介绍了MySQL - 将列拆分为多列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将列拆分为多个列,以便每列包含不同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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆