简体   繁体   中英

Redshift View Column Reassignment

I have an existing view with a column A that has values 'Y' or 'N'

I need to create another column B that is just the inverse of column A. So when A = 'Y' B = 'N'

Seems really simple but I cannot think of a way to do this within a view. I am trying to find a way to do it with a case that just says If column A = 'Y' then column B = 'N' and the other way around but am having issues

Anyone know of a good way to accomplish this?

You have the right idea. Assuming A only takes on 'Y' and 'N' :

create view invert_a as
    select (case when A = 'Y' then 'N' else 'Y' end) as B, . . .
    from t;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM