首页 > 解决方案 > SQL中连接的多列中的单列

问题描述

我有一个这样的表输出,这是多个表连接的结果。

+---------+------+--------+------+
|   Id    | V1   | V2     | V3   | 
+---------+------+--------+------+
|    1    | x1   | null   |  null|
|    2    | x2   | null   |  null|
|    3    | null | x3     |  null|
|    4    | null | x4     |  null|
|    5    | null | null   |  x9  |
+---------+------+--------+------+

我想得到一张这样的桌子。

+---------+------+
|   Id    | V    |  
+---------+------+
|    1    | x1   | 
|    2    | x2   | 
|    3    | x3   |
|    4    | x4   |
|    5    | x5   |
+---------+------+

这就是我目前正在做的事情。不知道如何使三列合并为一列。

select a.identifier, a.v1, b.v2, c.v3,
from table a
full join table b on a.identifier = b.identifier
full join table c on a.identifier = c.identifier
where a.v REGEXP 'some condition'

标签: sqljointeradata

解决方案


看看 - COALESCE() 函数,它返回列表中的第一个非空值。


推荐阅读