简体   繁体   中英

Replace a string value in a column by values from same column in another table

I am working on table that has following 3 columns:

ID         ACCESS                RGN
_________________________________________
abc       NOT_RESTRICTED        NOT_RESTRICTED
def          1                  W
ghi          MK                 SW
jkl          3001               N

I want to select values from RGN for a particular ID. When NOT_RESTRICTED, should return all other values in the RGN column from another table and will have similar values like W,SW and N else should return the corresponding value for a specific ID.

Any help is much appreciated. Thanks!

I think you need to join two tables conditionally as following:

Select t1.id, t1.access. t2 rgn
  From table t1 join table t2
    On t1.rgn = t2.rgn  Or t1.rgn = 'NOT_RESTRICTED'

This will do cross join when the rgn is NOT_RESTRICTED else give specific rgn.

Cheers!!

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