Oracle“不是GROUP BY表达式错误”

时间:2013-10-03 17:03:20

标签: sql oracle group-by sum

我有以下SQL表达式:

SELECT PROFESSOR_NAME, SUBJECT_NAME, NUMBER_OF_CREDITS, PERCENT,
  (SELECT COUNT(STUDENTID)
    FROM SUBJSTUD
    WHERE SUBJSTUD.SUBJECTID = SUBJECT.SUBJECT_ID) AS NUMBER_OF_STUDENTS,
  0.4*NUMBER_OF_CREDITS*PERCENT*(
    SELECT COUNT(STUDENTID)
    FROM SUBJSTUD
    WHERE SUBJSTUD.SUBJECTID = SUBJECT.SUBJECT_ID)*18/120) AS PAYMENT_PER_SUBJECT,
  SUM(0.4*NUMBER_OF_CREDITS*PERCENT*(
    SELECT COUNT(STUDENTID) 
    FROM SUBJSTUD
    WHERE SUBJSTUD.SUBJECTID = SUBJECT.SUBJECT_ID)*18/120) AS PAYMENT_PER_PROFESSOR
FROM SUBJECT, PROFESSOR, TEACHES
WHERE PROFESSOR.PROFESSOR_ID = TEACHES.PROFESSORID 
AND SUBJECT.SUBJECT_ID = TEACHES.SUBJECTID
AND POCETOK_UCEBNA = :UCEBNA_GODINA
AND SEMESTAR = :SEMESTAR
AND PROFESsOR.STUDISKAPROGRAMA = :STUDISKAPROGRAMA
GROUP BY PROFESSOR_NAME, SUBJECT_NAME, NUMBER_OF_CREDITS, PERCENT

参数取自列表框。没有SUM,它工作正常,但我需要最后的计算来生成一个报告,该报告将为每位教授的每个主题的所有付款总和。问题可能在子表达式(SELECT COUNT(STUDENTID) FROM SUBJSTUD WHERE SUBJSTUD.SUBJECTID = SUBJECT.SUBJECT_ID)中,但我不知道如何解决它。

1 个答案:

答案 0 :(得分:0)

您的查询中缺少开放括号,请尝试:

SELECT PROFESSOR_NAME, SUBJECT_NAME, NUMBER_OF_CREDITS, PERCENT,
  (SELECT COUNT(STUDENTID)
    FROM SUBJSTUD
    WHERE SUBJSTUD.SUBJECTID = SUBJECT.SUBJECT_ID) AS NUMBER_OF_STUDENTS,
  (0.4*NUMBER_OF_CREDITS*PERCENT*(
    SELECT COUNT(STUDENTID)
    FROM SUBJSTUD
    WHERE SUBJSTUD.SUBJECTID = SUBJECT.SUBJECT_ID)*18/120) AS PAYMENT_PER_SUBJECT,
  SUM(0.4*NUMBER_OF_CREDITS*PERCENT*(
    SELECT COUNT(STUDENTID) 
    FROM SUBJSTUD
    WHERE SUBJSTUD.SUBJECTID = SUBJECT.SUBJECT_ID)*18/120) AS PAYMENT_PER_PROFESSOR
FROM SUBJECT, PROFESSOR, TEACHES
WHERE PROFESSOR.PROFESSOR_ID = TEACHES.PROFESSORID 
AND SUBJECT.SUBJECT_ID = TEACHES.SUBJECTID
AND POCETOK_UCEBNA = :UCEBNA_GODINA
AND SEMESTAR = :SEMESTAR
AND PROFESsOR.STUDISKAPROGRAMA = :STUDISKAPROGRAMA
GROUP BY PROFESSOR_NAME, SUBJECT_NAME, NUMBER_OF_CREDITS, PERCENT;