从技术上讲,可以将递归CTE的结果用作括号内的子查询吗? (在MySql中)

时间:2018-11-09 13:44:10

标签: mysql subquery common-table-expression recursive-query

例如:

Select * From (
     WITH RECURSIVE cte_name AS (
              initial_query  -- anchor member
             UNION ALL
             recursive_query -- recursive member that references to the CTE name
        )
    SELECT * FROM cte_name
) A

1 个答案:

答案 0 :(得分:0)

处理WITH syntax for Common Table Expressions的MySql 8.0参考手册的13.2.13节提到以下内容:

  

在以下情况下允许WITH子句:   在子查询(包括派生表子查询)的开头:

SELECT ... WHERE id IN (WITH ... SELECT ...) ...
SELECT * FROM (WITH ... SELECT ...) AS dt ...

因此,这澄清了我的问题,因此将我自己的答案作为社区Wiki。