日期:2014-05-16  浏览次数:20504 次

group by max
本帖最后由 a291410855 于 2014-03-10 10:13:31 编辑
name     time      colother
test1    2013-3-3     msg1
test1    2013-3-4     msg2
test2    2013-3-5     msg3
test2    2013-3-6     msg4



select name,max(time) from tb group by name



这里我还想得到colother列的信息.应该怎么写?




------解决方案--------------------
select * from tb t where not exists(select 1 from tb  where name=t.name and time>t.time)

------解决方案--------------------

select a.*
 from tb a
 inner join
 (select name,
         max([time]) 'maxtime' 
  from tb
  group by name) b on a.name=b.name and a.[time]=b.maxtime