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

rsaldnfx  于 2021-07-27  发布在  Java
关注(0)|答案(1)|浏览(421)

我尝试在满足以下条件时使用select语句返回行:
第一个条件:员工的员工家庭组织不等于396000或396010,学位层次结构小于40,教员学位代码不等于“ms”或“ma”
第二个条件:员工的学位层次结构小于40,并且员工的教员科目代码和教员学位代码不在表SUBQUE code\U CROSSWARK中。
我得到以下错误:

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
zphenhs4

zphenhs41#

撇开可能有输入错误这一事实不谈,因为您使用同一别名两次连接表,查询中有语法错误。
第二个条件包含一个元组,但类型不正确。它应该在括号中,如 (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_CODE 以及 S.FACULTY_DEGREE_CODE 不包括空值。如果他们这样做了,这个语法就不会产生你想要的结果。您需要将此部分重新表述为“反连接”。

相关问题