ORA-00920: select 子句中的无效关系运算符具有多个连接并使用最大值

ORA-00920: invalid relational operator in select clause with multiple joins and using max value

当满足以下条件时,我尝试对 return 行使用 select 语句:

第一个条件: 员工的 EMPLOYEE_HOME_ORG 不等于 396000 或 396010 AND DEGREE_HIERARCHY 小于 40 AND FACULTY_DEGREE_CODE 不等于 'MS' 或 'MA'

第二个条件: 员工的 DEGREE_HIERARCHY 小于 40 并且员工的 FACULTY_SUBJECT_CODE 和 FACULTY_DEGREE_CODE 不在 table SUBJ_CODE_CROSSWALK.

我收到以下错误:

ORA-00920: invalid relational operator

请查看下面的代码,非常感谢任何帮助!

SELECT V.FACULTY_DEGREE_CODE,
      V.FACULTY_SUBJECT_CODE,
     I.EMPLOYEE_DEPARTMENT_HOME_ORG,
      MAX(D.DEGREE_HIERARCHY)
 FROM V_DEGRESS V
      JOIN DEGREE_CROSSWALK D
          ON V.FACULTY_DEGREE_CODE =
             D.DEGREE_CODE
      JOIN I_REPORT_DETAILS I
          ON V.PIDM = I.HR_PIDM
      LEFT JOIN SUBJ_CODE_CROSSWALK S
          ON V.FACULTY_DEGREE_CODE =
             S.FACULTY_DEGREE_CODE
      LEFT JOIN SUBJ_CODE_CROSSWALK S
          ON S.FACULTY_SUBJECT_CODE =
             V.FACULTY_SUBJECT_CODE
  WHERE     V.PERSON_SKEY = 12345

      AND            
     (  
       (I.EMPLOYEE_DEPARTMENT_HOME_ORG != 396000
        and I.EMPLOYEE_DEPARTMENT_HOME_ORG != 396010)
        and (d.DEGREE_HIERARCHY < 40 )
        and 
        (V.FACULTY_DEGREE_CODE != 'MS' and
            V.FACULTY_DEGREE_CODE != 'MA')
    )
             --and NOT ONE SUBJ CODE CROSSWALK
       AND  
       (
           (D.DEGREE_HIERARCHY < 40)      
           AND 
           (V.FACULTY_SUBJECT_CODE,
               V.FACULTY_DEGREE_CODE NOT IN
                    (SELECT S.FACULTY_SUBJECT_CODE,
                            S.FACULTY_DEGREE_CODE
                       FROM SUBJ_CODE_CROSSWALK
                            S
                      WHERE     S.FACULTY_SUBJECT_CODE =
                                V.FACULTY_SUBJECT_CODE
                            AND V.FACULTY_DEGREE_CODE =
                                S.FACULTY_DEGREE_CODE
                    )
             )
          )
GROUP BY V.FACULTY_DEGREE_CODE,
      V.FACULTY_SUBJECT_CODE,
      I.EMPLOYEE_DEPARTMENT_HOME_ORG

由于您使用相同的别名两次加入 table,因此可能存在拼写错误,除此之外,您的查询中存在语法错误。

第二个条件包含一个元组,但输入错误。它应该像 (V.FACULTY_SUBJECT_CODE, V.FACULTY_DEGREE_CODE) 一样放在括号中。变化:

AND 
       (V.FACULTY_SUBJECT_CODE,
           V.FACULTY_DEGREE_CODE NOT IN
                (SELECT S.FACULTY_SUBJECT_CODE,
                        S.FACULTY_DEGREE_CODE
                   FROM ...

对于:

AND 
       (V.FACULTY_SUBJECT_CODE,
           V.FACULTY_DEGREE_CODE) NOT IN
                (SELECT S.FACULTY_SUBJECT_CODE,
                        S.FACULTY_DEGREE_CODE
                   FROM ...

此外,您需要在最后删除一个括号以确保它们正确平衡。

注意: 您需要确保列 S.FACULTY_SUBJECT_CODES.FACULTY_DEGREE_CODE 不包含空值。如果他们这样做,此语法将不会产生您想要的结果。您需要将此部分改写为“反加入”。