0

我在另一个子查询中有一个带有子查询的查询。因此,底层子查询无法识别顶层子查询中的字段。我该如何解决?

SELECT codigo, descricao 
FROM statusplano sp, previsao pr
WHERE sp.codigo = pr.status
AND pr.plano = 13
AND sp.codigo = (SELECT codigo FROM statusplano sp1 WHERE ordem = (SELECT max(sp2.ordem) FROM statusplano sp2 WHERE sp2.codigo = pr.codigo AND pr.dataPrevista <= now()))

提前致谢。

4

1 回答 1

0

尝试这个

SELECT
codigo,
descricao
FROM sp2,
previsao pr
WHERE sp.codigo = pr.status
AND pr.plano = 13
AND sp.codigo = (SELECT
                   codigo
                 FROM sp2
                 WHERE ordem = (SELECT
                                  max(sp2.ordem)
                                FROM statusplano sp2
                                WHERE sp2.codigo = pr.codigo
                                    AND pr.dataPrevista <= now()))
于 2012-04-10T13:05:33.187 回答