[英]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:我正在处理具有以下 3 列的表:
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.我想从 RGN 中为特定 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.
当 NOT_RESTRICTED 时,应该从另一个表返回 RGN 列中的所有其他值,并且将具有类似的值,如 W、SW 和 N,否则应该返回特定 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.当
rgn
为NOT_RESTRICTED
时,这将进行交叉连接,否则给出特定的 rgn。
Cheers!!干杯!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.