select * from table1 t where exists(select 1 from table1 where t.Field1=Field1 and t.Field2>Field1)
select * from 表 a where not exist(select 1 from 表 b where a.name=b.name and b.id<a.id)
create table ##p(field1 varchar(50),field2 varchar(50))insert into ##p select 'aaa','123' union all select 'aaa','234' union all select 'bbb','234' union all select 'ccc','23' union all select 'bbb','444' /*相同的纪录取Field2最大的*/ select Field1, max(Field2) from ##p group by field1 /*相同的纪录取Field2最小的*/ select Field1, min(Field2) from ##p group by field1drop table ##p
我用这种方法不知道好不好,还请高手指教 SELECT a.* FROM Table1 a INNER JOIN Table1 b ON a.Field1 = b.Field1 AND b.ID< a.ID
create table ##p(field1 varchar(50),field2 varchar(50))insert into ##p select 'aaa','123'
union all select 'aaa','234'
union all select 'bbb','234'
union all select 'ccc','23'
union all select 'bbb','444'
/*相同的纪录取Field2最大的*/
select Field1, max(Field2) from ##p group by field1
/*相同的纪录取Field2最小的*/
select Field1, min(Field2) from ##p group by field1drop table ##p
SELECT a.*
FROM Table1 a INNER JOIN
Table1 b ON a.Field1 = b.Field1 AND b.ID< a.ID