0

次の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) にありますが、解決方法がわかりません。

4

1 に答える 1

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;
于 2013-10-03T17:16:35.590 に答える