如何在mysql中组合两个列并使其成为一个列?

wb1gzix0  于 2021-06-25  发布在  Mysql
关注(0)|答案(5)|浏览(351)
+-----+---------------+---------------+
| id  |    team_A     |    team_B     |
+-----+---------------+---------------+
|  1  |   Barcelona   |  Real Madrid  |
+-----+---------------+---------------+
|  2  |     Milan     |     Inter     |
+-----+---------------+---------------+

select * from table and combine as team_c

结果应该是一列。。

team_c as

barcelona
milam
real
inter

c组中的所有行应不同。。因为我需要在自动完成下拉列表中显示两个?

pinkon5k

pinkon5k1#

尝试此查询:

select a.team_a as team_c from table a Union select b.team_b from table b
fjaof16o

fjaof16o2#

SELECT CONCAT( team_A," ",team_B) AS team_c FROM table;

你可以试试这个输出会喜欢吗

巴塞罗那皇家马德里

米兰国际

4urapxun

4urapxun3#

SELECT team_A, team_B , CONCAT_WS('', team_A, team_B) AS team_C, from table;

您可以使用 CONCAT_WS . 希望它有用!

lc8prwob

lc8prwob4#

我认为这应该解决你的问题:

SELECT team_A AS team_C FROM table UNION SELECT team_B FROM table
zf2sa74q

zf2sa74q5#

为什么要将这些数据存储到额外的表中。您可以使用select查询

select team_a as team_c from table Union select team_b from table

相关问题