日期:2014-05-19  浏览次数:20466 次

求一条sql语句,谢谢!
比如下面的表
ID                           TIME
403 2006-12-22   17:29:46.000
403 2006-12-22   17:39:46.000
403 2006-12-22   16:06:46.000
201 2006-12-22   12:59:52.000
201 2006-12-22   12:59:55.000
403 2006-12-22   13:00:47.000
201 2006-12-22   13:00:55.000
403 2006-12-22   13:01:47.000
我只需要选择出如下的结果
403 2006-12-22   16:06:46.000
201 2006-12-22   12:59:52.000
对于一个ID只取一条记录,sql怎么写呢?



------解决方案--------------------
select * from table1 a where not exists(select 1 from table1 b where a.id=b.id and a.time <b.time)
------解决方案--------------------
select distinct(id),* from table1 where (speed> 20) and time between 'starttime ' and 'endtime '