日期:2014-05-18  浏览次数:20501 次

求一个sql语句~~~大侠拜托了。。。
比如有个表table
id col datetime
1 aa 2012-01-01
2 aa 2012-01-03
3 bb 2012-03-01
4 cc 2011-10-12
5 bb 2013-11-11

我要得到
2 aa 2012-01-03
5 bb 2013-11-11
4 cc 2011-10-12


就是col字段相同的,只取datetime最后的那一条记录~~拜托了~~

------解决方案--------------------
SQL code

select *
from tb t
where not exists (select 1 from tb where col=t.col and date>t.date)