select a.* 
from table1 a,(select rybh,tjxxid=max(tjxxid) from table1 group by rybh)b
where a.rybh=b.rybh and a.tjxxid=b.tjxxid

解决方案 »

  1.   

    select t.* from t,(select rybh,max(tjxxid) tjxxid from t group by rybh) a
    where t.rybh=a.rybh and t.tjxxid=a.tjxxid
      

  2.   

    --或者这样(这也是楼主自己写的那个语句的意思),但这样的效率差很多.select *
    from table1 a
    where tjxxid=(select tjxxid=max(tjxxid) from table1 where rybh=a.rybh)
      

  3.   

    SELECT a.*
    from 
    tb a,(select rybh,max(tjxxid) as tjxxid from tb group by rybh) b 
    where a.rybh=b.rybh and a.tjxxid=b.tjxxid