Edamame Edamame - 1 year ago 73
SQL Question

SQL / Impala : How to create a column using the existing column

I have a table like below:

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

I need to create a
with the logic:

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

Can this be done using SQL/Impala queries? If so, what should be the proper approach? Thanks!

Answer Source

If I'm not mistaken, impala supports 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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download