--建立测试环境
Create Table 表(ID varchar(10),ID1 varchar(10),Date varchar(10))
--插入数据
insert into 表
select '1','1','2005-2-1' union
select '2','2','2005-2-2' union
select '3','1','2005-2-3' union
select '4','2','2005-2-4' union
select '5','1','2005-2-2' union
select '6','2','2005-2-3'
select * from 表
--测试语句
select* from 表 a where exists(select id1,max(date) as maxdate from 表 group by id1
having id1=a.id1 and max(date)=a.date)
--删除测试环境
Drop Table 表