select 
    a.name,a.re 
from 
    表 a 
where 
    not exists(select 1 from 表 where name=a.name and id>a.id)
select
    a.name,a.re
from
    表 a,
    (select name,max(id) id from 表 group by name) b
where
    a.name=b.name and a.id=b.id

解决方案 »

  1.   

    谢谢,有没有简单一点的,比如用decode(???)之类的
      

  2.   

    select * from (select rank() over(partition by name order by id desc) rk,a.* from a) t where t.rk<=1;
      

  3.   

    select table.name,table.re from
         (select name,max(id) maxid from table group by name) temp,table 
    where table.name = temp.name and table.id = temp.maxid
      

  4.   

    为什么想的那么复杂
     select a.name,a.re from(select * from table where id in (select max(id) from table group by name) a;
      

  5.   

    select table.name,table.re from table where id in (select max(id) from table group by name);
      

  6.   

    select a.name,a.re
    from tb a join 
    (
    select name,max(id) maxid
    from tb
    group by name
    ) b
    on (a.name=b.name and a.id=b.maxid)