select id,uid,max(mydatetime),amount from table1 where uid=5 group by id,uid,amount;
结果是多条记录
请帮助
...全文
965打赏收藏
求一个单表的SQL语句
有表4个字段 id(主键) uid mydatetime amount 现在要找出uid=5的mydatetime最大的那条记录,表的记录比较多,求最高效写法。非高效写法也没有写出来 我的尝试: select id,uid,max(mydatetime),amount from table1 where uid=5 group by id,uid,amount; 结果是多条记录 请帮助
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