Column1 Column2
------- -------
apple juice
water melon
banana
red berry
我有一个包含两列的表格。 Column1 有一组词,Column2 也有一组词。我想用不带空格的 + 运算符将它们连接起来。
例如:苹果汁
问题是,如果第二列中有空值,我只想得到第一个元素作为结果。
例如:香蕉
Result
------
applejuice
watermelon
banana
redberry
但是,当我使用 column1 + column2 时,如果 Comunm2 为 NULL,它会给出 NULL 值。我想要“香蕉”作为结果。
最佳答案
使用 COALESCE 函数将 NULL 值替换为空字符串。
SELECT Column1 + COALESCE(Column2, '') AS Result
FROM YourTable
关于sql - 在 SQL 中连接 NULL 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8233746/