try :1.select  top 1 from tablename 
order by    日期  desc2.select top 1 
from tablename  a
where tablename.  日期  >a.  日期  

解决方案 »

  1.   

    select * from 表 a where not exists (select * from 表 where 编号=a.编号 and  日期>a.日期)
      

  2.   

    --创建临时表
    create table #tt (
    id varchar (255) null ,
    编号 varchar (255) null ,
    名称 varchar (255) null ,
    价格 varchar (255) null ,
    日期 smalldatetime null 
    )
    go--追加测试数据
    insert #tt ( id , 编号 , 名称 , 价格 , 日期 ) values ( '001' , '1011' , 'a' , '10.0' , '01  6 2005 11:00pm' )
    insert #tt ( id , 编号 , 名称 , 价格 , 日期 ) values ( '001' , '1011' , 'a' , '11.0' , '11  1 2005 11:12pm' )
    insert #tt ( id , 编号 , 名称 , 价格 , 日期 ) values ( '001' , '1012' , 'b' , '11.0' , '09  1 2005 10:05am' )
    insert #tt ( id , 编号 , 名称 , 价格 , 日期 ) values ( '001' , '1012' , 'b' , '11.0' , '10  3 2005  8:06am' )
    insert #tt ( id , 编号 , 名称 , 价格 , 日期 ) values ( '001' , '1012' , 'b' , '11.0' , '11  5 2005 11:09pm' )
    insert #tt ( id , 编号 , 名称 , 价格 , 日期 ) values ( '001' , '1012' , 'b' , '11.1' , '08  1 2004  1:10pm' )
    insert #tt ( id , 编号 , 名称 , 价格 , 日期 ) values ( '001' , '1012' , 'b' , '11.2' , '11  1 2005 11:12pm' )
    insert #tt ( id , 编号 , 名称 , 价格 , 日期 ) values ( '001' , '1012' , 'b' , '11.3' , '12  1 2005  9:10pm' )
    insert #tt ( id , 编号 , 名称 , 价格 , 日期 ) values ( '001' , '1013' , 'c' , '0.9' , '01  3 2005  6:03am' )--查询结果
    select * from #tt a 
    where not exists (select * from tt where 编号=a.编号 and 日期>a.日期)--删除临时表
    drop table #tt
    go
      

  3.   

    --测试环境
    create table lsdate
    (id nvarchar(5),
     bh int,
     name nvarchar(5),
     price money,
     date datetime)
    go
    insert lsdate
    select '001',1011,'a',10.0,'2005-01-06 23:00:00' union all
    select '001',1011,'a',11.0,'2005-11-01 23:12:12' union all
    select '001',1012,'b',11.0,'2005-09-01 10:05:18' union all
    select '001',1012,'b',11.0,'2005-10-03 08:06:00' union all
    select '001',1012,'b',11.0,'2005-11-05 23:09:17' union all
    select '001',1012,'b',11.1,'2004-08-01 13:10:00' union all
    select '001',1012,'b',11.2,'2005-11-01 23:12:12' union all
    select '001',1012,'b',11.3,'2005-12-01 21:10:10' union all
    select '001',1013,'c', 0.9,'2005-01-03 06:03:11' union all
    select '001',1013,'c', 0.7,'2005-11-01 10:28:09' 
    go
    --执行语句
    select  id,
    bh,
    name= (select top 1   name from lsdate l where bh = ls.bh and date in (select max(date) from lsdate where name = l.name group by bh) order by date),
    price=(select top 1  price from lsdate l where bh = ls.bh and date in (select max(date) from lsdate where name = l.name group by bh) order by date),
    date =(select top 1   date from lsdate l where bh = ls.bh and date in (select max(date) from lsdate where name = l.name group by bh) order by date)
    from lsdate ls
    group by bh,id
    go
      

  4.   

    不知道是不是这个意思,你试下select id,max(date) from table_name
    group by id
      

  5.   

    select * 
    from table1
    where 日期 = (select max(日期) from table ) group by 编号)
      

  6.   

    楼上的是在跟我说吗?
    我没有说大家不对
    这是我的个子查询我做了是对的大家帮我看下
    select * from lsdate where date in(
    select max(date) from lsdate
    group by id)
      

  7.   

    select * from table_name a,(select id,date=max(date)from table_name group by id) b
    where a.id=b.id and a.date=b.date
      

  8.   

    回复人:ColaPS(可乐) ( 一级(初级)) 信誉:100  2005-12-15 20:08:00  得分:0

    不知道是不是这个意思,你试下select id,max(date) from table_name
    group by id
      

  9.   

    select * from 表 where 编号+convert(char(19),日期,20) in(select 编号+convert(char(19),max(日期),20) from 表 group by 编号)