数据库: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的那些数据),非常感谢!
表名: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的那些数据),非常感谢!
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 )