0

我有四个 WITH 子句。我想知道是否可以在它们之间使用内部连接。

我在网上搜索,我找不到与此相关的任何内容。

甲骨文版本:11g

** 编辑 **

WITH
    GETDATABYDAY AS
    (
        select column1, column2
        from table1 
        where sales > 2000
     )
    SELECT
      column1,
      column2
    FROM
      GETDATABYDAY;

WITH
    GETDATABYDAY1 AS
    (
        select column3, column2
        from table1 
        where date between 'date1' and 'date2'
    )
    SELECT
        column3,
        column2
    FROM
        GETDATABYDAY1;

Assume that there are two more WITH named: GETDATABYDAY2 and GETDATABYDAY3

是否可以在所有 GETDATABYDAY、GETDATABYDAY1、GETDATABYDAY2 和 GETDATABYDAY3 上使用内部联接?

4

2 回答 2

2

像这样的东西会起作用:

with first_cte as ( 
    select ...
    from ...
), second_cte as (
    select ...
    from first_cte
      join some_table on ...
), third_cte as (
    select ...
    from ...
) fourth_cte as (
    select ...
    from some_other_table
      join second_cte on ...
) 
select ..
from fourth_cte
   join third_cte on ....
于 2012-05-31T13:56:29.690 回答
0

我认为它行不通,因为每个with clause 都是完全不同的查询的一部分。

您可以创建db views并使用它们而不是 with 子句。

于 2012-06-01T06:40:14.793 回答