去掉其他相似数据,保留最大时间数据
create table tb
(
id int
,date datetime
,dvalue int
)
insert into tb
select 1,'2011-12-30 19:29:00',1
union all select 1,'2011-12-30 19:36:00',2
union all select 2,'2011-12-30 20:29:00',3
union all select 2,'2011-12-30 20:31:00',4
union all select 3,'2011-12-30 21:00:00',5
union all select 4,'2011-12-30 22:00:00',6
union all select 5,'2011-12-30 23:00:00',7
-------显示结果-------
1,'2011-12-30 19:36:00',2
2,'2011-12-30 20:31:00',4
3,'2011-12-30 21:00:00',5
4,'2011-12-30 22:00:00',6
5,'2011-12-30 23:00:00',7
------解决方案--------------------让楼下来吧。
------解决方案--------------------
SQL code
select * from tb as t where not exists(select 1 from tb where ID=a.ID and (date>a.date or(Date=a.Date and dvalue>a.dvalue)))