合并 MySQL 中的两列并忽略 NULL

Merge two columns in MySQL and ignore the NULL

MySQL数据table如下:

Column1   Column2
A         NULL
B         NULL
NULL      C
NULL      D
NULL      NULL

需要输出如下:

Column3
A
B
C
D
NULL

我怎样才能得到这个合并?
MySQL 查询最好。
如果最后没有可用的选项,那么我可以寻找 python 代码。

select COALESCE(Column1, Column2) as Column3 from tablename

这是有效的。

您需要在 mysql 中的公共列和用例上连接表。 您可以执行以下操作..

CREATE TABLE new_tbl [AS] SELECT CASE
    WHEN orig_tbl1.col1 IS NOT NULL THEN orig_tbl1.col1
    WHEN orig_tbl1.col2 IS NOT NULL THEN orig_tbl1.col2
    ELSE NULL
    END , orig_tbl1.col2,orig_tbl1.col3,
 FROM orig_tbl1,orig_tbl2 where orig_tbl1.id = orig_tbl2.id ;

你可以试试这个 link。