我正在尝试创建一个查询,如果满足条件,该行将从表中删除。
伪代码:如果indexi
= 500并且user
= 290045,则从表1中删除,其中indexi
= 85并且user
= 290045
user | line_no | header | indexi |
-------+---------+--------+--------+
290045 | 0 | 0 | 500 |
290045 | 1 | 0 | 85 |
733 | 0 | 0 | 33 |
预期结果:
user | line_no | header | indexi |
-------+---------+--------+--------+
290045 | 0 | 0 | 500 |
733 | 0 | 0 | 33 |
我认为您想要exists
:
delete t
from mytable t
where
t.indexi = 85
and t.usr = 290045
and exists (select 1 from mytable t1 where t1.usr = t.usr and t1.indexi = 500)
附带说明:usr
是SQL Server中的保留字,因此不是列名的理想选择。