带一个as()是什么意思?

With a as () what is it mean?

这是一个单一的代码,但我把它分成了 3 个部分来描述。

我用了“With a as”
我的问题是: 它叫什么名字 ?它是函数还是什么?

因为我想要google它以获得更多关于它的解释

with a as ( 
 select 
             count(e.department_id) as cnt, 
             (select count(*) from employees e,departments d where e.department_id=d.department_id) as b_cnt 
      from employees e
      group by e.department_id,e.employee_id
     )
select 
       sum(cnt) as cnt,
       sum(b_cnt) as b_cnt
from a

这是一个 with 子句

The WITH clause, or subquery factoring clause, is part of the SQL-99 standard and was added into the Oracle SQL syntax in Oracle 9.2. The WITH clause may be processed as an inline view or resolved as a temporary table. The advantage of the latter is that repeated references to the subquery may be more efficient as the data is easily retrieved from the temporary table, rather than being requeried by each reference. You should assess the performance implications of the WITH clause on a case-by-case basis.

您可以在此处阅读更多内容:

https://oracle-base.com/articles/misc/with-clause

它通常被称为 CTE(通用 Table 表达式),但在 oracle 文档中您可以找到它作为 Subquery Factoring clause

更多示例:

SQL WITH 子句是由 Oracle 在 Oracle 9i 第 2 版数据库中引入的。 SQL WITH 子句允许您为 sub-query 块命名,可以在主 SQL 查询中的多个位置引用该名称。

文档 Link:
https://dba.stackexchange.com/questions/172521/difference-between-inline-view-and-with-clause