首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

这个SQL如何写

2012-02-03 
这个SQL怎么写原始数据id timeother2 2010-1-2a2 2010-1-3b3 2010-1-4c3 2010-1-2d4 2010-1-2e需要的结果

这个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; 

热点排行