简体   繁体   English

MySQL语法查询,用于将列合并为一个

[英]MySQL Syntax Query for Combining columns in one

Please. 请。 Help me. 帮我。 How to combine records of multiple columns in one new column ? 如何在一个新列中合并多个列的记录? In my table I have 3 columns named PIO1, PIO2 and PIO3. 在我的表中,我有3列名为PIO1,PIO2和PIO3。 So I want to combine the records of all three columns in one column. 因此,我想将所有三列的记录合并为一列。

This is my Column [1]: http://i.stack.imgur.com/JOnH4.png and this is the output what I want to show [2]: http://i.stack.imgur.com/aKUmB.png 这是我的专栏[1]: http : //i.stack.imgur.com/JOnH4.png ,这是我想显示的输出[2]: http : //i.stack.imgur.com/aKUmB .png

If you need records of all columns in same column, use UNION ALL 如果需要同一列中所有列的记录,请使用UNION ALL

SELECT PIO FROM
(
    SELECT id as 'id', PIO1 as 'PIO' FROM tbl_name
    UNION ALL
    SELECT id as 'id', PIO2 as 'PIO' FROM tbl_name
    UNION ALL
    SELECT id as 'id', PIO3 as 'PIO' FROM tbl_name
) a 
ORDER BY id

Try this 尝试这个

alter table <tablename> add combocolumn varchar(3000);

update <tablename> set combocolumn = concat (PO1,PO2,PO3);

This assumes that "combine" means concatenate without adding a separator, and that 3000 characters will be enough. 假设“ combine”表示串联而未添加分隔符,则3000个字符就足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM