select id,max(time) 'time',max(select flag from 表 where A.id=id,max(A.time)=time) 'flag' from 表 A group by id

解决方案 »

  1.   

    select * from tablename where id in(select max(id) from tablename group by id);
      

  2.   

    select b.id,b.time,a.flag from yourtable a join 
    (select id,max(time) as time from yourtable group by id)b 
    on a.id=b.id and a.time=b.time
      

  3.   

    不好意思写错了,select * from tablename where id||time in(select id||max(time) from tablename group by id);
      

  4.   

    select * from tablename where id+time in(select id+max(time) from tablename group by id)
      

  5.   

    select * from yourtable a where [time]=(select max([time]) from yourtable where [id]=a.[id])
      

  6.   

    漏了个and
    select id,max(time) 'time',max(select flag from 表 where A.id=id and max(A.time)=time) 'flag' from 表 A group by id