27,582
社区成员




create table tb(a int,b int,c int,d int,e varchar(10),f varchar(10))
insert into tb values(1,1,2,1,'a','a')
insert into tb values(1,2,1,2,'a','b')
insert into tb values(1,3,1,1,'b','d')
insert into tb values(1,4,1,3,'a','c')
insert into tb values(2,1,1,2,'e','f')
insert into tb values(2,2,2,1,'x','z')
insert into tb values(2,3,1,1,'w','q')
go
select t.* from tb t where not exists(select 1 from tb where a = t.a and (c < t.c or (c= t.c and d < t.d) ) )
drop table tb
/*
a b c d e f
----------- ----------- ----------- ----------- ---------- ----------
1 3 1 1 b d
2 3 1 1 w q
(所影响的行数为 2 行)
*/