select distinct * from tablename a
where cre_date=(select max(cre_date) from tablename where unitid=a.unitid)
order by cre_date desc

解决方案 »

  1.   

    select unitid,max(cre_date) from tablename group by unitid order by max(cre_date) desc
      

  2.   

    如果全部显示出来呢,cre_date最新的放在前面,unitid相同要在一起
    如表是这样:
    unitid     cre_date
    aa         2000-03-22
    aa         2000-03-12
    bb         2000-03-20
    bb         2000-03-18
    cc         2000-03-23
    cc         2000-03-22
    结果是这样:
    unitid     cre_date
    cc         2000-03-23
    cc         2000-03-22
    aa         2000-03-22
    aa         2000-03-12
    bb         2000-03-20
    bb         2000-03-18
    怎么写呢?
      

  3.   

    select distinct * from yourttable order by unitid ,    cre_date
      

  4.   

    如果有相同的UNITID,和CRE_DATE呢?
    aa         2000-03-22
    aa         2000-03-22
    aa         2000-03-12
    bb         2000-03-20
    bb         2000-03-18
    cc         2000-03-23
    cc         2000-03-22显示:
    unitid     cre_date
    cc         2000-03-23
    cc         2000-03-22
    aa         2000-03-22
    aa         2000-03-22
    aa         2000-03-12
    bb         2000-03-20
    bb         2000-03-18
      

  5.   

    select unitid,max(cre_date) from tablename group by unitid order by cre_date
      

  6.   

    select * from yourttable order by unitid ,cre_date
    就可以列出全部了。