test acc
test acc

Reputation: 591

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?

Upvotes: 0

Views: 26

Answers (1)

Kamil Gosciminski
Kamil Gosciminski

Reputation: 17147

You need a CASE WHEN statement:

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

Upvotes: 3

Related Questions