如何加入OpenEdge SQL的第一行?

时间:2014-06-26 04:05:10

标签: sql openedge

加入SQL中的第一行应该与简单地加入内部选择

一样简单
select so_nbr, sod_line last_line
  from so_mstr
  join sod_det on sod_det.rowid = (select top 1 sod_det.rowid
                                     from sod_det
                                    where sod_nbr = so_nbr
                                    order by sod_line desc) x
 where so_ord_date > curdate() - 60

不幸的是,我得到了:Error code -20302, SQL state HY000: [DataDirect][OpenEdge JDBC Driver][OpenEdge] TOP clause used in unsupported context. (13694)

注意,我被困在OE10.1C上,无法升级。

1 个答案:

答案 0 :(得分:1)

根据Abe Voelker's Answer

  

OpenEdge 11.2增加了对OFFSET and FETCH clauses的支持   到SQL SELECT查询;低于11.2的OpenEdge版本没有   支持OFFSET / FETCH

     

来自11.2 product documentation   " SQL参考"文件:

The OFFSET clause specifies the number of rows to skip, before starting to return rows
from the query expression. The FETCH clause specifies the number of rows to return,
after processing the OFFSET clause.
     

值得注意的是, TOPOFFSET / FETCH条款是   互斥 - TOP不能在使用的查询中使用   OFFSETFETCH

试试这个

  SELECT so_nbr,sod_line As last_line
  FROM so_mstr
       JOIN sod_det ON sod_det.rowid = (SELECT sod_det.rowid 
                                        FROM sod_det WHERE sod_nbr = so_nbr
                                        ORDER BY sod_line Desc 
                                        FETCH FIRST 1 ROWS ONLY) x
  WHERE so_ord_date > curdate() - 60