Search code examples
sqlhivehqlhiveql

Possible to specify multiple values for select as query


SELECT my_col = 'D' AS test FROM db.table;

Let's say this is my query.

At the moment, test will be either true or false. However, I want the column test to be of value val_a if true or val_b if false.

Is this possible / how would this be done?


Solution

  • You need a CASE WHEN statement:

    select
      case when my_col = 'D' then val_a else val_b end as test
    from db.table