同等条件有多条数据,他们只有一个字段不一样就是time字段,本人想根据time字段查到最新一条,怎么查询,求高手解答
解决方案
10
select t1.* from tablename t1
from(select c1,c2,max(time) max_time from tablename group by c1,c2 )t2
where t1.c1=t2.c1 and t1.c2=t2.c2 and t1.time =t2.max_time;
from(select c1,c2,max(time) max_time from tablename group by c1,c2 )t2
where t1.c1=t2.c1 and t1.c2=t2.c2 and t1.time =t2.max_time;
20
不是分组那更好办了,你每次只查询出来一条数据嘛?假如是这样子,就order by time desc limit 1;
select t1.* from tablename t1 where t1.c1=xxx and t2.c2=xxx order by time desc limit 1;
5
5
表结构是什么
select * from tt a where not exists(select 1 from tt where a.f1=f1 and a.time<time)
select * from tt a where not exists(select 1 from tt where a.f1=f1 and a.time<time)