![](/img/trans.png)
[英]Oracle: Sql to update row of the same table based on value from another row of the same table
[英]oracle sql - update same table based on another attribute value
我在oracle中有一个表,该表具有4个具有以下值的属性
attribute_a attribute_b attribute_c attribute_d
abcd1 1 0
abcd1 2 1
abcd1 3 0
def1 1 1
def1 2 1
我想根据attribute_c中的值将具有“逻辑AND”值的attribute_d更新为attribute_d
即对于abcd1,逻辑与为0。我想在attribute_d中使用abcd1的值更新为0的表
对于def1,我想用def1的attribute_d中的值1更新表。 我可以使用MERGE来完成此操作吗?如果有人可以给我一个查询,我们将不胜感激。
首先,我同意@jarlh关于存储计算值的评论。
解:
UPDATE [TableName]
SET attribute d = (CASE WHEN attribute_b = attribute c THEN 1 ELSE 0 END)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.