为什么子查询在DB2中的ON子句中不起作用

为什么子查询在DB2中的ON子句中不起作用,db2,subquery,on-clause,Db2,Subquery,On Clause,为什么这个简单的查询在oracle中运行良好,但在DB2中不起作用: select * from sysibm.dual d1 left join sysibm.dual d2 on 1=1 and exists (select 1 from sysibm.dual) 将包含条件的子查询移动到where子句可能会有所帮助,但这将限制外部联接到内部。当我尝试运行您的查询时,我得到一个,根据信息中心的链接,on子句有以下限制: 与JOIN运算符关联的ON子句或MERGE语句中的ON子句 由于

为什么这个简单的查询在oracle中运行良好,但在DB2中不起作用:

select * 
from 
sysibm.dual d1 
left join sysibm.dual d2 on 1=1 and exists (select 1 from sysibm.dual)

将包含条件的子查询移动到where子句可能会有所帮助,但这将限制外部联接到内部。

当我尝试运行您的查询时,我得到一个,根据信息中心的链接,on子句有以下限制:

与JOIN运算符关联的ON子句或MERGE语句中的ON子句 由于以下原因之一无效

* The ON clause cannot include any subqueries.
* Column references in an ON clause must only reference columns
  of tables that are in the scope of the ON clause.
* Scalar fullselects are not allowed in the expressions of an ON clause.
* A function referenced in an ON clause of a full outer join 
  must be deterministic and have no external action.
* A dereference operation (->) cannot be used.
* A SQL function or SQL method cannot be used.
* The ON clause cannot include an XMLQUERY or XMLEXISTS expression.
我不确定您的查询是否可行,但您是否认为您可以重新编写以下内容:

select * 
from 
sysibm.dual d1 
left join (
    SELECT dl.*,
    CASE WHEN EXISTS (SELECT 1 FROM sysibm.dual)
         THEN 1
         ELSE 0
    END AS jn
    FROM sysibm.dual dl
) D2
  on 1=1 and 1=d2.jn

当我尝试运行您的查询时,我得到一个,根据信息中心的see链接,on子句有以下限制:

与JOIN运算符关联的ON子句或MERGE语句中的ON子句 由于以下原因之一无效

* The ON clause cannot include any subqueries.
* Column references in an ON clause must only reference columns
  of tables that are in the scope of the ON clause.
* Scalar fullselects are not allowed in the expressions of an ON clause.
* A function referenced in an ON clause of a full outer join 
  must be deterministic and have no external action.
* A dereference operation (->) cannot be used.
* A SQL function or SQL method cannot be used.
* The ON clause cannot include an XMLQUERY or XMLEXISTS expression.
我不确定您的查询是否可行,但您是否认为您可以重新编写以下内容:

select * 
from 
sysibm.dual d1 
left join (
    SELECT dl.*,
    CASE WHEN EXISTS (SELECT 1 FROM sysibm.dual)
         THEN 1
         ELSE 0
    END AS jn
    FROM sysibm.dual dl
) D2
  on 1=1 and 1=d2.jn
这在DB2V10.1中有效! 没有安装补丁包。

这在DB2V10.1中有效!
没有安装fixpack。

我可以重写它,但我认为将子查询作为表连接可能导致完全扫描。我有一些抽象的例子:1从帐户中选择*在o.acc_id=a.acc_id上的联接操作o,并存在从acc_id=o.acc_id具有maxope_日期的操作中选择null=o.ope_日期2从帐户中选择*在o.acc_id=a.acc_id上的联接操作o选择maxope_日期作为ope_日期,acc_id=o.acc_id=o.acc_id和latestope.ope_date=o.ope_date第二个会导致完全扫描,因为我认为第二个查询可以像SELECT*from accounts a JOIN operations o.acc_id=a.acc_id其中o.ope_date=SELECT MAXope_date from operations d其中o.acc_id=d、 acc_id如果您有一个包含o.acc_id和o.ope_date的索引,那么DB2将使用该索引来解析最大值。我们这里有一个类似的表$work,一个类似的查询运行得非常快。我可以重写它,但我认为将子查询作为表连接可能导致完全扫描。我有一些抽象的例子:1从帐户中选择*在o.acc_id=a.acc_id上的联接操作o,并存在从acc_id=o.acc_id具有maxope_日期的操作中选择null=o.ope_日期2从帐户中选择*在o.acc_id=a.acc_id上的联接操作o选择maxope_日期作为ope_日期,acc_id=o.acc_id=o.acc_id和latestope.ope_date=o.ope_date第二个会导致完全扫描,因为我认为第二个查询可以像SELECT*from accounts a JOIN operations o.acc_id=a.acc_id其中o.ope_date=SELECT MAXope_date from operations d其中o.acc_id=d、 acc_id如果您有一个包含o.acc_id和o.ope_date的索引,那么DB2将使用该索引来解析最大值。我们在$work中有一个类似的表,类似的查询运行得非常快。