为什么内联视图与其他视图不同?将其命名为视图有什么用

why inline view is different from other views?what is the use of naming it as a view

据我所知,内联视图不是数据库对象,它就像在 from 子句中编写子查询一样,那么将其命名为视图有什么用。简单地说,我们可以将其称为子查询。

这是 Oracle 命名约定。来自 Inline View and Subquery:

An inline view is a SELECT statement in the FROM-clause of another SELECT statement. In-line views are commonly used to simplify complex queries by removing join operations and condensing several separate queries into a single query.

This feature is commonly referred to in the MSSQL community as a derived table, and in the Postgres community simply refers to it as a subselect (subselects are inline views + subqueries in Oracle nomenclature).

A subquery (sub-query) is a SELECT statement in the WHERE- or HAVING-clause of another SELECT statement.

因此,当您将它与 FROM 一起使用时,它被称为 inline view:

SELECT * 
  FROM ( SELECT deptno, count(*) emp_count
         FROM emp
         GROUP BY deptno ) emp,
       dept
 WHERE dept.deptno = emp.deptno;

当您将它与 WHERE/HAVING 一起使用时,它被称为 subquery:

SELECT ename, deptno 
  FROM emp 
 WHERE deptno = (SELECT deptno 
                   FROM emp 
                  WHERE ename = 'TAYLOR');