ACCESS数据库,有一列是日期字段,要求用SQL语句按照这个日期找出最近一次和最近两次的记录

解决方案 »

  1.   

    select top 1 * from xx order by 这个日期 desc
    select top 2 * from xx order by 这个日期 desc
      

  2.   

    和 jinjazz(近身剪(充电中...)一样的想法,使用排序
      

  3.   

    忘了说,库里面不是只按照这一个日期来找,结构是这样的字段1  字段1日期
    a         2005-1-1
    a         2005-1-2
    a         2005-1-3
    b         2005-3-1
    b         2005-3-2
    b         2005-3-3
    是要把每个a和b的第1或第2次的记录找出来
      

  4.   

    select 字段1,字段1日期 from
    (
    select (select count(1)+1 from 表1 where 字段1日期>a.字段1日期 and 字段1=a.字段1) as 次序,* from 表1 a
    )
    where 次序<=2最近1条改为  次序=1
      

  5.   

    select top 1 rq from table where 字段1='a'  order by rq descselect top 2 rq from table where 字段1='b'  order by rq desc