列入表:
id,name,date
1 , a  ,2013.05.06
2 , b  ,2013.05.08
3 , c  ,2013.05.05
4 , a  ,2013.07.08目标:
需要排除重复,根据date获取最新数据。我需要最新的数据
id,name,date
2 , b  ,2013.05.08
3 , c  ,2013.05.05
4 , a  ,2013.07.08
然后我用sql语句无论是用到DISTINCT 还是group by来查询最后都达不到条件
我最后得到的结果都是
id,name,date
1 , a  ,2013.05.06
2 , b  ,2013.05.08
3 , c  ,2013.05.05求指点~~~~~~

解决方案 »

  1.   

    select id,name,date from 表 as a exist(select id ,name,max(date) from 表 where id = a.id group by name,id having max(date) = a.date)
      

  2.   

    但是之后我怎么拿出他的maxdate呢?
      

  3.   

    但是之后我怎么拿出他的maxdate呢?
    select b.id,b.name,b.date from 表 as a exist(select id ,name,max(date) as date from 表 where id = a.id group by name,id having max(date) = a.date) as b
    b.data就是maxdate
      

  4.   


    select id,name,"date" from(
    select id,name,"date",row_number()over(partition by name order by "date" desc) rn from ax
    ) where rn=1
    order by id; 
            ID NAME date
    ---------- ---- ----------
             2 b    2013.05.08
             3 c    2013.05.05
             4 a    2013.07.08
      

  5.   

    SELECT T.NAME, MAX(t.date_) from test T GROUP BY t.NAME