你几乎可以编写查询完全按照你描述的那样:
declare @t1 table(itemid varchar(7),storeid varchar(9),MSRTime varchar(3))
insert into @t1(itemid,storeid,MSRTime) values
('x','y','z')
declare @t2 table(itemid varchar(7),storeid varchar(9),MSRTime varchar(3))
insert into @t2(itemid,storeid,MSRTime) values
('x','y','z'),
('a','b','c')
declare @t3 table(itemid varchar(7),storeid varchar(9),MSRTime varchar(3),status varchar(4))
insert into @t3(itemid,storeid,MSRTime,status) values
('x','y','z','D'),
('a','b','c','D')
delete from t2
from @t2 t2
inner join
@t3 t3
on
t2.itemid = t3.itemid and
t2.storeid = t3.storeid and
t2.MSRTime = t3.MSRTime and
t3.status = 'D'
where
not exists (
select *
from @t1 t1
where t1.itemid = t2.itemid and
t1.storeid = t2.storeid and
t1.MSRTime = t2.MSRTime
)
select * from @t2
结果:
itemid storeid MSRTime
------- --------- -------
x y z
我认为这可能为我工作。谢谢你的帮助。当我在真实案例中测试时,我会接受答案。 – Amir
谢谢你它为我的魅力工作。 – Amir