子查询因子:内部相互联接

时间:2012-05-31 13:38:47

标签: oracle view oracle11g subquery-factoring

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

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

Oracle版: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上使用内连接?

2 个答案:

答案 0 :(得分: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 ....

答案 1 :(得分:0)

我认为它不起作用,因为每个with clause都是完整不同查询的一部分。

您可以创建db views,并使用它们代替with子句。