我已经搜索了这个问题的答案,但在任何地方都找不到。反正不是我想要的。
我在一个表中有五个 Mysql 列,我想将它们组合成一列。
column1value | column2value | column3value | column4value | column5value
需要成为
column1valuecolumn2valuecolumn3valuecolumn4valuecolumn5value
在一列(第 1 列)中。我需要每一行都发生这种情况。
提前谢谢了。
我已经搜索了这个问题的答案,但在任何地方都找不到。反正不是我想要的。
我在一个表中有五个 Mysql 列,我想将它们组合成一列。
column1value | column2value | column3value | column4value | column5value
需要成为
column1valuecolumn2valuecolumn3valuecolumn4valuecolumn5value
在一列(第 1 列)中。我需要每一行都发生这种情况。
提前谢谢了。
如果您只想检索以这种方式组合的数据:
SELECT CONCAT(
column1value,
column2value,
column3value,
column4value,
column5value
) column1value
FROM my_table
如果要永久更新表中的数据:
UPDATE my_table
SET column1value = CONCAT(
column1value,
column2value,
column3value,
column4value,
column5value
)
如果您还想删除旧列:
ALTER my_table
DROP column2value,
DROP column3value,
DROP column4value,
DROP column5value
你可以那样做
select concat(column1value,column2value,column3value,column4value,column5value)
AS allvalues from table1
全部在第 1 列
UPDATE my_table
SET column1 = CONCAT(column1value,column2value,column3value,column4value,column5value
)