sql查询

fcy6dtqo  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(308)

我有一个查询,如果满足条件,它应该返回一行。此查询比较3个表中的列,并应使用degree\u hierarchy的最大值,因为可以有多个值。然后它应该在where子句中使用max(degree\u层次结构)来满足条件。
到目前为止,我的代码有一个错误:

[Error] Execution (1: 8): ORA-00937: not a single-group group function

感谢您的帮助,谢谢!

SELECT V.FACULTY_DEGREE_CODE,
        V.FACULTY_SUBJECT_CODE,
        I.EMPLOYEE_DEPARTMENT_HOME_ORG,
        MAX(D.DEGREE_HIERARCHY)

   FROM V_degrees  V
        JOIN DEGREE_CROSSWALK D
            ON V.FACULTY_DEGREE_CODE =
               D.DEGREE_CODE
        JOIN I_DETAILS I
            ON V.ID = I.HR_ID
        INNER JOIN  SUBJ_CROSSWALK  S
             ON V.FACULTY_DEGREE_CODE =
              S.FACULTY_DEGREE_CODE
            INNER JOIN SUBJ_CROSSWALK  S
                ON S.FACULTY_SUBJECT_CODE =
                   V.FACULTY_SUBJECT_CODE
  WHERE V.PERSON_id = 12345
  AND 
  (
   (I.EMPLOYEE_DEPARTMENT_HOME_ORG != '396000'
    OR I.EMPLOYEE_DEPARTMENT_HOME_ORG != '396010'
    ) and
    (DEGREE_HIERARCHY > 30)
  )
  AND 
  (
    (DEGREE_HIERARCHY > 30) AND
    (NOT EXISTS (SELECT FACULTY_SUBJECT_CODE, FACULTY_DEGREE_CODE 
                FROM SUBJ_CROSSWALK  S
                WHERE S.FACULTY_SUBJECT_CODE = V.FACULTY_SUBJECT_CODE
                AND
                V.FACULTY_DEGREE_CODE = S.FACULTY_DEGREE_CODE)
    )
  )
9cbw7uwe

9cbw7uwe1#

中的未聚合列 SELECT 列表必须存在于 GROUP BY 条款。。。你忘了加。最后加上:

GROUP BY V.FACULTY_DEGREE_CODE,
         V.FACULTY_SUBJECT_CODE,
         I.EMPLOYEE_DEPARTMENT_HOME_ORG

相关问题