select top  1 ID,Title,Content,Times,Resours,NewTypeID  from News where NewTypeID=1 and id<165  order by ID desc; 为什么总是报这样的错误:from keyword not found where expected? 错误的线条在1的下面,我想实现的是一个记录的上一条和下一条

解决方案 »

  1.   

    select top 1 ID,Title,Content,Times,Resours,NewTypeID from News where NewTypeID=1 and id<165 order by ID desc;oracle不支持TOP 1
      

  2.   

    select * from (select  ID,Title,Content,Times,Resours,NewTypeID from News where NewTypeID=1 and id<165 order by ID desc) where rownum <2;
      

  3.   

    用分析函数:lead和lag看看/* Formatted on 2011-7-13 17:38:32 (QP5 v5.114.809.3010) */
    SELECT   segment1,
             creation_date,
             LEAD (segment1) OVER (ORDER BY creation_date) next_segment1,
             LAG (segment1) OVER (ORDER BY creation_date) per_segment1,
             LEAD (creation_date) OVER (ORDER BY segment1) next_creation_date,
             LAG (creation_date) OVER (ORDER BY segment1) per_creation_date
      FROM   apps.po_headers_all
     WHERE   org_id = '106'
             AND creation_date BETWEEN TO_DATE ('2011-1-1', 'yyyy-mm-dd')
                                   AND  TO_DATE ('2011-2-1', 'yyyy-mm-dd')
      order by 1  --这段SQL可以找出前一张PO以及后一张PO的订单号、创建时间。
      

  4.   

    top 是 ACCESS 支持的
    oracle 用 rowum 小于。 只能=1 ,不能大于。
      

  5.   

    分析函数  Lag和Lead函数可以在一次查询中取出同一字段的前N行的数据和后N行的值