查询在Teradata中工作,但不在Oracle中工作

时间:2016-04-22 09:56:38

标签: sql oracle

如果我执行以下代码,我可以获得所需的输出;但在甲骨文面临着一个错误:

SELECT NAME
  FROM STUD
 WHERE ID IN (
                 SEL DISTINCT  TAB1.ID  
                FROM (
                              SEL A.ID
                                , B.SALARY
                             FROM Fr   A
                       INNER JOIN PACK B ON A.ID = B.ID
                     ) AS TAB1
          INNER JOIN (
                              SEL A.FRIEND_ID
                                , B.SALARY
                             FROM Fr    A
                       INNER JOIN PACK  B ON A.FRIEND_ID = B.ID
                     ) AS TAB2
                  ON TAB2.SALARY > TAB1.SALARY
      )
    ;

面对oracle中的以下错误:     ORA-00907:缺少右括号

1 个答案:

答案 0 :(得分:1)

您有两个错误:SEL而非SELECT以及使用AS关键字的表别名,Oracle不支持

SELECT NAME
  FROM STUD
 WHERE ID IN (SELECT DISTINCT  TAB1.ID  FROM
(SELECT A.ID , B.SALARY
FROM
Fr   A
INNER JOIN
PACK B
ON
A.ID = B.ID)  TAB1
INNER JOIN
(SELECT A.FRIEND_ID , B.SALARY
FROM
Fr  A
INNER JOIN
PACK  B
ON
A.FRIEND_ID = B.ID
)  TAB2
ON
TAB2.SALARY > TAB1.SALARY
)

除此之外,我认为您在内部查询中不需要DISTINCT,因为您只在IN子句中使用它