因为MYSQL4.0.18 不支持嵌套子查询 , 如果要实现, 只能通过临时表了 create Tempory table tb2 as select attid , max(lasttime ) as lastime1 from tb1 group by attid;select distinct tb1.* from tb1,tb2 where tb1.attid = tb2.attid and tb1.lasttime = tb2.lasttime1;我只想到这个方法, 望高手指点一下
select a.attid ,a.userid,a.lasttime from tb1 a,tb1 b where a.attid=b.attid and a.lasttime>b.lasttime group by attid having max(b.lasttime)<a.lasttime
create Tempory table tb2
as
select attid , max(lasttime ) as lastime1 from tb1 group by attid;select distinct tb1.* from tb1,tb2 where tb1.attid = tb2.attid and tb1.lasttime = tb2.lasttime1;我只想到这个方法, 望高手指点一下
from tb1 a,tb1 b
where a.attid=b.attid and a.lasttime>b.lasttime
group by attid
having max(b.lasttime)<a.lasttime