select from_unixtime(logtime) as logtime,id from t_log where id in (select id from t_acc) order by logtime desc limit 0,1;这个Sql得到的内容为:
+---------------------+-----------+
| logtime             |        id |
+---------------------+-----------+
| 2009-08-16 01:59:17 |    514000 |
+---------------------+-----------+我要得到的每个ID的最后一条登录时间现在只能得到t_log中的最后一条信息。。
请问要怎么修改呀?

解决方案 »

  1.   

    select from_unixtime(logtime) as logtime,id from t_log a where a.id in (select b.id from t_acc b) and not exists (select 1 from t_log c where c.id=a.id and c.logtime>a.logtime)
      

  2.   

    select * from unixtime(logtime) as logtime,id from t_log,(select id,min(currdate()-unixtime(logtime)) from t_log) t1  where id in (select id from t_acc) and t1.id=t_log.id; 
      

  3.   

    1楼的运行速度太慢了
    2楼的。。那个。。Sql没问题嘛?select * from unixtime(logtime) as logtime,id from t_log这个看不懂。。没写错嘛?
      

  4.   

    select max(from_unixtime(logtime)) as lastlogtime,id 
    from t_log 
    where id in (select id from t_acc) 
    group by id
      

  5.   

    4楼的。。Group By还能logtime吗?
      

  6.   

    怎么不能logtime?
    不就是求每个ID是最后一次登陆时间吗?
    等价于每个ID的最大时间
      

  7.   

    select from_unixtime(logtime) as logtime,id from t_log where id in (select id from t_acc) order by logtime desc limit 0,1; 写法2:
    select from_unixtime(logtime) as logtime,id from t_log a, t_acc b,(select id,max(logtime) as logtime2 from t_log group by id) c where a.id=b.id and a.id=c.id and a.logtime=c.logtime2写法3:select from_unixtime(a.logtime) as logtime,a.id from t_log a where a.id in (select b.id from t_acc b) and a.logtime=(select max(c.logtime) from t_log c where c.id=a.id)
      

  8.   

    select from_unixtime(Max(logtime)) as logtime,id from t_log where id in (select id from t_acc) Group By id;