我有一个包含 3 列的表,这些列的值可以为空。我必须创建第 4 列并仅连接那些不为空的列的值。 预期输出:
col1 col2 col3 col4
----------------------------------------------------
1 0 1 col1=True;col2=False;col3=True;
0 Null 1 col1=False;col3=True
最佳答案
使用concat_ws()
:
select concat_ws(';',
concat('col1=', elt(col1 + 1, 'false', 'true')),
concat('col2=', elt(col2 + 1, 'false', 'true')),
concat('col3=', elt(col3 + 1, 'false', 'true'))
)
from t;
关于mysql - 如果不为空,如何通过插入文本和其他列中的值的组合来更新 mysql 表中的列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47752209/