USE TEMPDB
go
IF OBJECT_ID(N'#TEST', N'U') IS NOT NULL
DROP TABLE dbo.#TEST
CREATE TABLE #TEST
(NAME VARCHAR(50),
line int,
RANKS INT)
INSERT INTO #TEST
(name, line,RANKS)
VALUES
('Tom',1, 1), --keep
('Tom',2, 1),--keep
('Toms',1, 0), --keep
('Toms',2, 0),--keep
('Dave',1, 0),--delete
('Dave',2, 0),--keep
('Dave',1, 1),--keep
('TIm',1,1),--keep
('TIm',1,0),--delete
('Matt',1,0),--delete
('Matt',1,1)--keep
答案 0 :(得分:1)
这样的事情应该有效:
delete t1
from #TEST t1
where exists(select *
from #TEST t2
where t2.NAME = t1.NAME
and t2.line = t1.line
and t2.RANKS <> t1.RANKS)
and t1.RANKS = 0;