1

我正在为 Oracle 查询而苦苦挣扎。我想向内部查询发送一个值,但没有成功。我的查询如下所示:

SELECT * FROM Pro u 
LEFT JOIN (SELECT * FROM PROLOG d
WHERE d.Id = (SELECT MAX(Id) FROM PROLOG t
          WHERE t.Project = **u.Id** 
          AND t.Prodstatus IN    (5,40)))z ON (u.ID = z.Project)
WHERE u.Id = 22;

我想 u.Id用 22 替换。值 22 来自 Pro u 表。请给我一些提示。

4

2 回答 2

1

我不相信您可以将联接与内联视图相关联,但是您可以将 SQL 语句简化为具有相关谓词的简单外部联接:

SELECT * 
FROM pro u 
LEFT OUTER JOIN prolog d 
    ON d.project = u.id
    AND d.Id = (SELECT MAX(Id) 
                    FROM prolog t
                    WHERE t.project = u.id
                    AND t.prodstatus IN (5,40))
WHERE u.id = 22;
于 2013-01-31T22:26:48.470 回答
0

您不需要将该值传递给Pro表中的子查询,您可以使用prolog表值

SELECT * FROM Pro u 
LEFT JOIN (SELECT * FROM PROLOG d
WHERE d.Id = (SELECT MAX(Id) FROM PROLOG t
          WHERE t.Project = d.Project 
          AND t.Prodstatus IN    (5,40)))z ON (u.ID = z.Project)
WHERE u.Id = 22;
于 2013-01-31T22:00:27.543 回答