更新行对中的一行,其中两行一起满足特定条件 [英] Update one row of a row pair, where both rows together meet certain criteria
问题描述
如何获取具有特定规格的一对行的两个 ID?
How do I obtain both ids of a pair of rows with certain specs?
更具体:
id - spec1 - spec2 - spec 3
1 null 30 nov 34
2 null 30 nov 34
3 null 1 dec 35
4 75 1 dec 35
我想更新具有相同日期且没有任何行具有 spec1 值的行的 spec3.
I want to update spec3 of the rows that have the same date and where none of the rows has a value for spec1.
在本例中:我想更新第 1 行和第 2 行 -> 相同日期,spec1 没有值
In the case of this example: I want to update row 1 and 2 -> same date, no values for spec1
我不想更新第 3 行和第 4 行 -> 相同的日期但第 4 行有一个 spec1 的值
I don't want to update row 3 and 4 -> same date BUT row 4 has a value for spec1
推荐答案
您可以从此查询中获取 id
you can get the id(s) from this query
从 tbl a 中选择 a.id id,表在哪里a.spec2 = b.spec2 和isnull(a.spec1) 和 isnull(b.spec1) 和a.id != b.id;
select a.id id from tbl a, tbl b where a.spec2 = b.spec2 and isnull(a.spec1) and isnull(b.spec1) and a.id != b.id;
这篇关于更新行对中的一行,其中两行一起满足特定条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!