我想匹配表的第一列,并将表2的值插入表1。但如果表2的值为空,请保持表1的值不变。我正在使用配置单元来完成此操作。请帮助。
3zwjbxry1#
你需要使用 coalesce 获取要填充的非空值 b column 以及 case 决定填充的语句 c column .例子:
coalesce
b column
case
c column
hive> select t1.a, coalesce(t2.y,t1.b)b, case when t2.y is null then t1.c else t2.z end as c from table1 t1 left join table2 t2 on t1.a=t2.x;+----+-----+----+--+| a | b | c |+----+-----+----+--+| a | xx | 5 || b | bb | 2 || c | zz | 7 || d | dd | 4 |+----+-----+----+--+
hive> select t1.a,
coalesce(t2.y,t1.b)b,
case when t2.y is null then t1.c
else t2.z
end as c
from table1 t1 left join table2 t2 on t1.a=t2.x;
+----+-----+----+--+
| a | b | c |
| a | xx | 5 |
| b | bb | 2 |
| c | zz | 7 |
| d | dd | 4 |
1条答案
按热度按时间3zwjbxry1#
你需要使用
coalesce
获取要填充的非空值b column
以及case
决定填充的语句c column
.例子: