小弟遇到一个较基础的问题
就是从复合条件的记录中过滤出
距离当前日期最近的(最新的)一条记录,
我试过top关键字,但oracle中好像没有这个关键字,
请各位大侠帮小弟一下,万分感谢!

解决方案 »

  1.   

    select * from a where date_a =(select max(date_a ) from a)
      

  2.   

    select * from a where date_a=(select max(date_a) from a where to_char(date_a,'yyyymmdd')<=to_char(sysdate,'yyyymmdd'));是这个意思吗?
      

  3.   

    用rownum = 1
    例如:
    select * from table
    where ....
    and rownum = 1
      

  4.   

    select * from table
    having rownum = max(rownum)
      

  5.   

    lyq_lawrance(lawrance) 的效率太低,Select id
                    From table a,
                    (select id,max(date) As date 
                    from table
                    where Date Between Pi_Startdate And Pi_Enddate 
                    group by id) b
                    where a.id=b.id and
                    a.date =b.date
      

  6.   

    select * from table
    having rownum = max(rownum)是可以取最大的一个,但我是取最大的N(N>1)条那该怎么写呢,
    MSSQL这方面要比ORACLE好很多
      

  7.   

    如果使用rownum,则使用以下语句即可:
    select * from (select * from table order by date desc) where rownum=1;
      

  8.   

    select * from table_a where rownum<10
    最后where rownum代替top