如何在PL/SQL中加入子查询?

发布于 2024-10-08 16:56:45 字数 279 浏览 5 评论 0原文

我需要在oracle中加入子查询。这不起作用我收到连接操作的语法错误

select s1.key, s1.value, s2.value 
from ((select key, value
        from tbl 
        where id = 1) as s1
join 
    (select key, value
        from tbl 
        where id = 2) as s2
on s1.contract = s2.contract);

i need to join subqueries in oracle. This does not work i get a syntax error for the join operation

select s1.key, s1.value, s2.value 
from ((select key, value
        from tbl 
        where id = 1) as s1
join 
    (select key, value
        from tbl 
        where id = 2) as s2
on s1.contract = s2.contract);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

转身泪倾城 2024-10-15 16:56:45

您应该在内联视图中选择要加入的字段 (contract):

SELECT  s1.key, s1.value, s2.value 
FROM    (
        SELECT contract, key, value
        FROM   tbl 
        WHERE  id = 1
        ) as s1
JOIN    (
        SELECT  contract, key, value
        FROM    tbl 
        WHERE   id = 2
        ) as s2
ON     s1.contract = s2.contract

You should select the field you are joining on (contract) in the inline views:

SELECT  s1.key, s1.value, s2.value 
FROM    (
        SELECT contract, key, value
        FROM   tbl 
        WHERE  id = 1
        ) as s1
JOIN    (
        SELECT  contract, key, value
        FROM    tbl 
        WHERE   id = 2
        ) as s2
ON     s1.contract = s2.contract
羞稚 2024-10-15 16:56:45

你的括号太多了。

SELECT
  s1.key, 
  s1.value, 
  s2.value 
FROM (SELECT 
        key, 
        value
      FROM tbl 
      WHERE id = 1) AS s1
JOIN (SELECT 
        key, 
        value
      FROM tbl 
      WHERE id = 2) AS s2
  ON s1.contract = s2.contract;

You had one too many sets of Parenthesis.

SELECT
  s1.key, 
  s1.value, 
  s2.value 
FROM (SELECT 
        key, 
        value
      FROM tbl 
      WHERE id = 1) AS s1
JOIN (SELECT 
        key, 
        value
      FROM tbl 
      WHERE id = 2) AS s2
  ON s1.contract = s2.contract;
单挑你×的.吻 2024-10-15 16:56:45

去掉最外面的括号。

Get rid of the outer most parenthesis.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文