select a.* from tablename as a,(select id,max([date]) as date from tablename) as b
where a.[date]=b.[date]

解决方案 »

  1.   

    不行啊! (select id,max([date]) as date from tablename)这一句是不是就出错了?
      

  2.   

    select id form tabename where  date in (select min(date) from tablename)
      

  3.   

    select aa.* from test as aa,(SELECT id,max(date) as date FROM TEST group by id )as bb where aa.[date]=bb.[date]
      

  4.   


    select aa.* 
    from TEST as aa,(SELECT id,max(date) as date from TEST group by id )as bb 
    where aa.[date]=bb.[date]把test换成你的表名。
      

  5.   

    不行阿,我换了啊!表里有60条记录,可是用这个方法查出了1770条记录来!
    我用的是DB2数据库,我想应该根SQL语句没有太大关系吧!
      

  6.   

    --就你上面的数据,下面肯定可以出结果。(在Ms SQLServer里)。  Select ID,Max(Date),Name From Test Group by ID,Name
      

  7.   

    SQL SERVER中肯定可以这样:
    select id,max(date),name from 表 group by id,name
      

  8.   

    select t1.id, t1.date, t1.name
    from tbl t1
    where exists (select *
    from tbl t2
    where t2.id = t1.id
    group by t2.id
    having t1.date = max(t2.date))
    试试!
      

  9.   

    select t1.id, t1.date, t1.name
    from 表 a
    where not exists (select 1
    from 表 b
    where a.id = b.id and a.date<b.date
    )
      

  10.   

    按ID分组,取每组DATE最大值
    select id,max(date) 
    from table
    group by id
      

  11.   

    select * from yourtable AA where [date]=(select max([date] from yourtable BB
    where AA.id=BB.id)
      

  12.   

    select * from yourtable AA where [date]=(select max([date]) from yourtable BB
    where AA.id=BB.id)
      

  13.   

    select id,max(date1),name from test group by id,name
      

  14.   

    97866(weiLuang)的语句可以用了,谢谢大家的帮助!现在封贴了!