使用CTE到另一個CTE的引用 - SQL - Use a reference of a CTE to another CTE -开发者知识库

使用CTE到另一個CTE的引用 - SQL - Use a reference of a CTE to another CTE -开发者知识库,第1张

Is it possible in SQL use a reference inside a Common Table Expression inside another C.T.E in the same query? Here there is an example:

在SQL中,是否可能在另一個C.T.中使用公共表表達式中的引用E在同一個查詢中?這里有一個例子:

WITH CT1 AS (SELECT * FROM T),
     CT2 AS (SELECT * FROM CT1)

SELECT * FROM CT2;

I tried this in SQLite3 and it works, I just wanted to know if it's part of standard SQL. Any advices concerning this argument will be highly appreciated. Thank you very much!

我在SQLite3中嘗試過,它很有用,我只是想知道它是否是標准SQL的一部分。對於這一論點的任何建議都將受到高度贊賞。非常感謝!

1 个解决方案

#1


7  

Here are three important properties of CTEs:

CTEs有三個重要的特性:

  • You can refer to a CTE in subsequent CTEs or in the main body of the query.

    您可以在后續的CTE或查詢的主體中引用CTE。

  • You can refer to any given CTE multiple times.

    你可以參考任何給定的CTE多次。

  • The CTE can be used in a from clause at any level of nesting within other subqueries.

    CTE可以在from子句中用於其他子查詢中的任何嵌套級別。

The CTEs -- as with everything in SQL -- need to be defined before they are used. So, you cannot define them in random order.

CTEs(與SQL中的所有內容一樣)需要在使用之前定義。所以,你不能以隨機順序來定義它們。

This is the standard definition of CTEs and does a good job of explaining how they are used across databases. Those three properties are key ways that they differ from subqueries.

這是CTEs的標准定義,並且很好地解釋了如何跨數據庫使用它們。這三個屬性是它們與子查詢不同的關鍵方式。

最佳答案:

本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复