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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4510782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 08:39:53  来源:igfitidea点击:

How to join sub-queries in PL/SQL?

sqljoinplsqlsubquery

提问by mrt181

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

我需要在 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);

回答by Quassnoi

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

您应该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

回答by John Hartsock

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;

回答by Parris Varney

Get rid of the outer most parenthesis.

去掉最外面的括号。