oracle with 子查詢用法
subquery_factoring_clause
The WITH
query_name
clause lets you assign a name to a subquery block. You can then reference the subquery block multiple places in the query by specifying the query name. Oracle Database optimizes the query by treating the query name as either an inline view or as a temporary table.
You can specify this clause in any top-level SELECT
statement and in most types of subqueries. The query name is visible to the main query and to all subsequent subqueries except the subquery that defines the query name itself.
Restrictions on Subquery Factoring This clause is subject to the following restrictions:
You can specify only one
subquery_factoring_clause
in a single SQL statement. You cannot specify aquery_name
in its own subquery. However, anyquery_name
defined in thesubquery_factoring_clause
can be used in any subsequent named query block in thesubquery_factoring_clause
.In a compound query with set operators, you cannot use the
query_name
for any of the component queries, but you can use thequery_name
in theFROM
clause of any of the component queries.
oracle 給出的一個示例:
Subquery Factoring: Example The following statement creates the query names dept_costs
and avg_cost
for the initial query block containing a join, and then uses the query names in the body of the main query.
WITH dept_costs AS ( SELECT department_name, SUM(salary) dept_total FROM employees e, departments d WHERE e.department_id = d.department_id GROUP BY department_name), avg_cost AS ( SELECT SUM(dept_total)/COUNT(*) avg FROM dept_costs) SELECT * FROM dept_costs WHERE dept_total > (SELECT avg FROM avg_cost) ORDER BY department_name;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/197458/viewspace-1020053/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle子查詢Oracle
- Laravel 子查詢語句用法Laravel
- Oracle with重用子查詢Oracle
- 子查詢-表子查詢
- Oracle查詢轉換(五)子查詢展開Oracle
- Oracle OCP(08):使用子查詢Oracle
- Oracle_Day2 子查詢Oracle
- 【SQL】Oracle查詢轉換之 OR用法SQLOracle
- 原創:oracle 子查詢介紹Oracle
- 複雜查詢—子查詢
- ORACLE_OCP之SQL_子查詢OracleSQL
- 15、Oracle中的高階子查詢Oracle
- Oracle 樹形結構查詢的特殊用法Oracle
- SQL查詢的:子查詢和多表查詢SQL
- 相關子查詢&非相關子查詢概念
- oracle 9i與10g,11g不同的子查詢括號用法Oracle
- MySQL子查詢MySql
- 子串查詢
- 使用子查詢
- MYsql 子查詢MySql
- 查詢子串
- 子查詢分解
- 11子查詢
- sql子查詢SQL
- informix子查詢ORM
- Oracle OCP(14):使用子查詢檢索資料Oracle
- Oracle not exist子查詢全掃的優化Oracle優化
- MySQL聯結查詢和子查詢MySql
- select查詢之三:子查詢
- mysql-分組查詢-子查詢-連線查詢-組合查詢MySql
- 區分關聯子查詢和非關聯子查詢
- sql語法相關子查詢與非相關子查詢SQL
- exist-in和關聯子查詢-非關聯子查詢
- 從Oracle 11.2.0.4 BUG到Oracle子查詢展開分析Oracle
- MySQL之連線查詢和子查詢MySql
- Gremlin -- 常用查詢用法REM
- 巢狀子查詢巢狀
- GORM subquery 子查詢GoORM