查询表中相同字段按时间排序(时间最大)的记录
表 executions
id build_id tester_id execution_ts status testplan_id tcversion_id
653 114 1 2011-05-29 19:36:42 p 3609 8469
654 114 1 2011-05-29 19:39:15 f 3609 8469
如果要查询出tcversion_id相同记录中 execution_ts 时间最大的那条记录,请问sql如何写?
以下sql语句查询出来的结果不正确
SELECT id,tcversion_id ,MAX(execution_ts) ,status FROM executions GROUP BY tcversion_id
该方法可以查询出,但速度特别慢,executions有10万条数据,查询时间至少半个小时了,不可行,请高手赐教!
select * from executions t
where not exists (select 1 from executions where tcversion_id=t.tcversion_id and execution_ts>t.execution_ts)