我有两个表:
主题
STDID SUBJID SEMESTER_YEAR GRADE FREQ STATUS
1111 2 2/2018 6 75 ok
1111 13 2/2018 7 100 ok
1111 4 1/2018 5 90 ok
1111 7 1/2018 10 95 ok
1111 9 2/2018 8 75 ok
1122 2 2/2017 3 75 no
1122 13 2/2017 5 100 ok
1122 4 1/2017 5 90 ok
1122 7 1/2017 10 95 ok
1122 9 2/2017 8 75 ok
1113 2 2/2018 6 75 ok
1113 13 2/2018 7 100 ok
1113 4 1/2018 5 90 ok
1113 7 1/2018 4 95 no
1113 9 2/2018 8 75 ok
1132 2 2/2018 3 75 no
1132 13 2/2018 7 100 ok
1132 4 1/2018 5 90 ok
1132 7 1/2018 4 95 no
1132 9 2/2018 8 75 ok
另一个:学生
STDID NAME DATA_NASC
1111 gabriel 12-APR-70
1112 pedro 12-JUN-70
1113 lucas 12-MAR-70
1114 mariana 12-FEB-70
1115 klemer 12-SEP-70
1116 jose 12-DEC-70
1117 vitor 12-NOV-70
1118 artur 12-APR-70
1119 bia 12-NOV-70
1120 julia 12-MAR-70
1121 rafaela 12-JAN-70
1122 augusto 12-FEB-70
1123 eneas 12-JUL-70
1124 zezinho 12-APR-70
1125 hugo 12-APR-70
1126 matheus 12-APR-70
1127 diana 12-APR-70
1128 andre 12-APR-70
1129 reco 12-APR-70
我正在尝试创建一个程序,在给定一个学期/学年的情况下,针对该学期内的每个科目(SUBJID),输出这些科目的学生ID,学生姓名及其各自的等级,频率和状态。对于列出的每个科目,我还需要显示该科目的学生平均成绩
已经做到了,但是我被困住了,希望有人可以帮助我进行程序和选择:
SELECT STUDENT.NAME
, SUBJECT.STDID
, SUBJECT.SUBJID
, SUBJECT.SEMESTER_YEAR
, AVG(SUBJECT.GRADE)
OVER (PARTITION BY SUBJECT.SUBJID) AS AVERAGE_GRADE_BY_SUBJ
FROM SUBJECT, STUDENT
WHERE SUBJECT.SEMESTER_YEAR = '1/2018'
AND SUBJECT.STDID = STUDENT.STDID
ORDER BY SUBJECT.SUBJID;
我需要的输出示例:
NAME STDID SUBJID SEMESTER_YEAR AVERAGE_GRADE_BY_SUBJ
gabriel 1111 4 1/2018 5
lucas 1113 4 1/2018 5
marcello 1132 4 1/2018 5
lucas 1113 7 1/2018 6,5
marcello 1132 7 1/2018 6,5
gabriel 1111 7 1/2018 6,5