sql/impala:如何使用现有列创建列

twh00eeo  于 2021-06-26  发布在  Impala
关注(0)|答案(1)|浏览(279)

我有一张如下的table:

id  |  field_A  |  field_B  
----------------------------
1   |   Brown   |  Black
2   |   Blue    |  White
3   |   Red     |  Black

我需要创建一个 field_C 按照逻辑:

if (field_A is not null):
    field_C = field_A
else:
    field_C = field_B

这可以使用sql/impala查询完成吗?如果是这样,应该采取什么适当的方法?谢谢!

7kjnsjlb

7kjnsjlb1#

如果我没弄错的话, impala 支架 case :

selec id, field_a, field_b,
      case when field_a is not null then field_a
           else field_b
      end as field_c
from yourtable

相关问题