表1  table1id  proid  proname1    AAA    啊啊啊
2    BBB    额额额
表2  table2id           uptime
AAA   2011-08-05 17:17:17
AAA   2011-08-05 17:17:20
AAA   2011-08-05 17:18:17
BBB   2011-08-05 17:20:18
BBB   2011-08-05 17:50:19
现在我要得出  AAA,BBB 最后一次修改的时间。有高手赐教吗。我头疼了。做了一天SQL语句。

解决方案 »

  1.   

    Select id, max(uptime) From table2 Group by id
      

  2.   

    select t1.id,t1.proname, t2.maxdate
    from table1 t1
    inner join 
    (select id,max(uptime) maxdate from table2 group by id) t2
    on t1.proid=t2.id
      

  3.   

    select a.* from table2 a where not exists(select 1 from tb where [id] = a.id and uptime> a.uptime)
      

  4.   


    select proid,proname,MAX(uptime) from table1 a left join table2 b on a.proid = b.id group by proid
      

  5.   

    select id,Max(uptime) from table2 group by id