【问题标题】:How do I join to a first row in OpenEdge SQL?如何加入 OpenEdge SQL 的第一行?
【发布时间】:2014-08-16 11:26:43
【问题描述】:

在 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 上,无法升级。

【问题讨论】:

    标签: sql openedge


    【解决方案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
    

    【讨论】:

    • 很遗憾,我们现在是 10.1C,没有机会升级。有没有办法在以前版本的 OpenEdge 上实现这一点?
    猜你喜欢
    • 1970-01-01
    • 2011-01-03
    • 2011-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多