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

解决方案 »

  1.   

    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)))
      

  2.   

    --DROP TABLE tb
    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',7select * from tb as a where not exists(select 1 from tb where ID=a.ID and (date>a.date or(Date=a.Date and dvalue>a.dvalue)))/*
    id date dvalue
    1 2011-12-30 19:36:00.000 2
    2 2011-12-30 20:31:00.000 4
    3 2011-12-30 21:00:00.000 5
    4 2011-12-30 22:00:00.000 6
    5 2011-12-30 23:00:00.000 7
    */
      

  3.   

    谢谢roy_88,我的少了 Date=a.Date and dvalue>a.dvalue 这个了。