0

我编写了一个使用 WITH 子句的简单查询,但出现此错误:

错误:错误:缺少表“cte”的 FROM 子句条目

这是查询,我清楚地在其中放置了一个 FROM 子句。我知道这一定很简单,但我只是没有看到我做错了什么。谢谢。

WITH cte AS (
    SELECT cident, "month"
    FROM orders_extended io
    WHERE io.ident = 1    -- 1 will be replaced with a function parameter
)
SELECT *
FROM orders_extended o
WHERE o.cident = cte.cident AND o."month" = cte."month"
ORDER BY o."month" DESC, o.cname
4

1 回答 1

1

消息没有说谎。

WITH cte AS (
    SELECT cident, "month"
    FROM orders_extended io
    WHERE io.ident = 1    -- 1 will be replaced with a function parameter
)
SELECT o.*
FROM orders_extended o
INNER JOIN cte ON (o.cident = cte.cident and o."month" = cte."month")
ORDER BY o."month" DESC, o.cname
于 2013-09-13T15:53:02.657 回答