简体   繁体   English

用另一个表中同一列的值替换列中的字符串值

[英]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.rgnNOT_RESTRICTED时,这将进行交叉连接,否则给出特定的 rgn。

Cheers!!干杯!!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用另一个表中的多个值替换列值 - DB2 - Replace a column value with multiple values from another table - DB2 如何将列中的所有字符串值替换为另一个值? - How to replace all string values from a column to another value? 触发器:将新插入的列中的 null 值替换为同一行中的另一列值 - Trigger: Replace null values in column from new insert with another column value from SAME row 用同一张表中另一个列的数据替换列数据 - Replace a column data with data from another column in the same table mysql 如果另一个表的某个列中的任何值包含相同的“字符串”,则需要添加包含“string”的列 - Need to add column which contains “string” if any of the values in a certain column from another table contain that same “string” 用另一个表中的列值替换列的空值 - Replace nulls of a column with column value from another table 检查列值并更新同一表中的另一个列值 - Check column value and update another column value from same table INNER JOIN可以用同一个表中的另一个值替换列的值 - 对于所有行 - Can INNER JOIN replace a column's value with another value from the same table - for all rows 如何用同一视图表 (SQL) 中另一个字段(不同列)的值替换一个字段中的值? - How to replace a value in one field by a value from another field (different column) within the same view table (SQL)? SQL-查询并用从同一表中提取的另一个值替换列值 - SQL - query and replace column value with another value extracted from the same table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM