我有四个 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 上使用内部联接?
这样的事情会起作用:
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 ....
我认为它不起作用,因为每个with clause
都是一个完全不同的查询的一部分。
不过,您可以创建db views
,并使用它们而不是 with 子句。