[英]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.