WITH子句的正常使用是通过其备用名称子查询factoring来显示的。当我们想在查询中多次使用子查询时,比如两次使用子查询时,它们非常方便
whatever IN ( sub-query )
过滤器。
这不适用于您的情况,因此您可以简单地将CTE转换为内联视图:
SELECT
name,
SUM(order) as TOTAL,
SUM(num) as NUM,
QUANT
from (
SELECT
a.name,
w.order as order,
s.num as num,
w.id,
(Select count(*)
from quant
where id = w.id and trunc(date) between :P99_DATE_FROM and :P99_DATE_TO) as QUANT
FROM
web w
left outer JOIN tabel_1 a ON a.id = w.id
left outer JOIN tabel_2 s ON s.id = w.id
WHERE
(trunc(s.date) between :P99_DATE_FROM and :P99_DATE_TO
or :P99_DATE_FROM is null or :P99_DATE_TO is null)
) cte
group by name,QUANT