我以前没有使用过SQLite
并且无法弄清楚语法,如果有帮助,我会在SQL Server
中使用它。
我需要将结果放入临时表中,以便重用它们。
// SQL Server
WITH FT_CTE AS
(
SELECT pID, cID FROM brFTNode_Children
WHERE pID = 1
UNION ALL
SELECT e.pID, e.cID FROM brFTNode_Children e
INNER JOIN FT_CTE ftCTE on (ftCTE.cID = e.pID)
)
SELECT * INTO #ParentChild FROM FT_CTE;
// SQLite尝试
WITH FT_CTE AS
(
SELECT pID, cID FROM brFTNode_Children
WHERE pID = 1
UNION ALL
SELECT e.pID, e.cID FROM brFTNode_Children e
INNER JOIN FT_CTE ftCTE on (ftCTE.cID = e.pID)
)
CREATE TEMPORARY TABLE ParentChild as SELECT * FROM FT_CTE;
我得到Error near "CREATE": syntax error
答案 0 :(得分:16)
CREATE TABLE statement不允许使用CTE,但SELECT会执行:
CREATE TEMPORARY TABLE ParentChild AS
WITH FT_CTE AS (
SELECT pID, cID FROM brFTNode_Children
WHERE pID = 1
UNION ALL
SELECT e.pID, e.cID FROM brFTNode_Children e
INNER JOIN FT_CTE ftCTE ON (ftCTE.cID = e.pID)
)
SELECT * FROM FT_CTE;