数据库:ACCESS
表名:test有如下字段和记录:
ID proCode price fabuDate
10 001 1.45 2008-09-05
11 002 2.67 2008-09-05
12 003 1.89 2008-09-05
13 004 3.85 2008-09-05
14 001 1.48 2008-09-06
15 002 2.89 2008-09-06
16 003 1.50 2008-09-06
17 004 3.95 2008-09-06
...
我要取出离当前日期最近的日期的记录(以上面数据为例子,即是取2008-9-6的那些数据),非常感谢!

解决方案 »

  1.   

    select max(fabudate) from test where fabudate <= 当前日期
      

  2.   

    这样只是一个fabudate字段,我要所有字段
      

  3.   

    set nocount on
    declare @test table(ID int, proCode varchar(10), price money, fabuDate datetime) 
    insert @test select 10, '001', 1.45, '2008-09-05' 
    insert @test select 11, '002', 2.67, '2008-09-05' 
    insert @test select 12, '003', 1.89, '2008-09-05' 
    insert @test select 13, '004', 3.85, '2008-09-05' 
    insert @test select 14, '001', 1.48, '2008-09-06' 
    insert @test select 15, '002', 2.89, '2008-09-06' 
    insert @test select 16, '003', 1.50, '2008-09-06' 
    insert @test select 17, '004', 3.95, '2008-09-06' 
    insert @test select 18, '004', 3.95, '2008-09-07' 
    insert @test select 19, '004', 3.95, '2008-09-07' 
    select * from @test where fabuDate in(select max(fabuDate) from @test  )
      

  4.   

    ?要这么复杂么,并且日期我是不知道的,还有数据库是ACCESS的哦
      

  5.   

    呵呵,搞定了,;谢谢jiashijie 的提示select * from t_price where fabutm=(select max(fabutm) from t_price where fabutm<=#" & date() & "#)不过不知道是否有更简洁或更有效率的写法,欢迎得到赐教