我有一张如下表:
ID Value1 Value2 Value3
1 abc null null
1 null def null
1 null null ghi
我想只选择单行中的非空值,即输出应如下所示:
ID Value1 Value2 Value3
1 abc def ghi
是否可以使用sql实现相同的目标?
答案 0 :(得分:1)
试试这个
select id,
max(value1) as value1,
max(value2) as value2,
max(value3) as value3
from table
group by id
答案 1 :(得分:1)
SELECT ID,
MAX(Value1) AS Value1,
MAX(Value2) AS Value2,
MAX(Value3) AS Value3
FROM your_table
GROUP BY ID
<强> Demo 强>