有什么方法可以明智地合并行吗?

Any way to achieve coalesce row wise?

我有一个table

| ID  |  V1  |  V2   |   
| 100 |  1   |  1    |
| 100 | null |  1    |
| 101 | null |  null |
| 101 |  1   |  1    |
| 102 |  1   |  null |
| 102 |  1   |  null |

需要样本输出:

ID 100 在至少一行中有 V1 值,因此需要 1

相同 ID 101 在至少一行中有 V1 值,因此需要 1

ID 102 在两行中都没有 V2 值,因此需要 null

需要输出

| ID  |  V1  |  V2   |
| 100 |  1   |  1    |
| 101 |  1   |  1    |
| 102 |  1   |  null |

尝试将这些值组合成一个列表并获得最大值

有没有更简单的函数可以实现这个?

您可以进行聚合:

select id, max(v1) as v1, max(v2) as v2
from table t
group by id;
select ID, max(V1) as V1, max(V2) as V2 from table group by ID;