日期:2014-05-16 浏览次数:20838 次
select * from table1 where uid=5 order by mydatetime desc limit 1
------解决方案--------------------
高效的做法就是uid上必须有索引
------解决方案--------------------
select a.id,a.uid,a.mydatetime,a.amount from test15 a inner join
(select uid,max(mydatetime) tm from test15 where uid=5) b
on a.uid=b.uid and a.mydatetime=b.tm where a.uid=5
------解决方案--------------------
如果为了提高效率,则需要创建 (uid,mydatetime)的索引。