读书人

这个SQL如何写

发布时间: 2012-02-03 22:02:47 作者: rapoo

这个SQL怎么写
原始数据
id time other
2 2010-1-2 a
2 2010-1-3 b
3 2010-1-4 c
3 2010-1-2 d
4 2010-1-2 e
需要的结果是
id time other
2 2010-1-3 b
3 2010-1-4 c
4 2010-1-2 e

每个id只取一项,这项是关于时间最新的。

[解决办法]

SQL code
select * from table a where not exists(select 1 from table where id=a.id and time>a.time) order by a.id; 

读书人网 >Mysql

热点推荐