我有一张表,存储不同考试的学生成绩,不同的考试类型,比如主考、持续评估、课程作业等,我需要查询这个表格,这样我就只能得到一个特定考试单元的一行,根据学生参加考试的次数,平均百分比是多少。下面是我尝试的查询:
select stu_reg_no, unit_code,
exam_unit, exam_semester,
student_year,
sum(per_centage_score)/count(per_centage_score) percentage
from student_results_master
group by unit_code, exam_unit,
per_centage_score, stu_reg_no,
exam_semester, student_year;这是我的成果集:

对于同一个考试单元,我有两行,因为一个是主要考试,另一个是课程作业,我需要这样的输出:
E35/1000/2013 TFT001 COMPLEX ANALYSIS 1 1 71.04
E35/1000/2013 TFT002 LINEAR ALGEBRA 1 1 56.25该单位的百分比加在一起,除以该单位的考试次数。我怎样才能做到这一点?
发布于 2013-10-10 08:24:41
Oracle提供了一个内置函数,用于计算一组行- AVG()上的表达式的平均值。要获得所需的输出,您需要做以下两件事:
sum(per_centage_score)/count(per_centage_score)替换为avg(per_centage_score)per_centage_score子句中删除group by列。为此,您的查询可能如下所示:
select stu_reg_no
, unit_code
, exam_unit
, exam_semester
, student_year
, avg(percentage) percentage
from student_results_master
group by unit_code
, exam_unit
, stu_reg_no
, exam_semester
, student_year;结果:
STU_REG_NO UNIT_CODE EXAM_UNIT EXAM_SEMESTER STUDENT_YEAR PERCENTAGE
------------- --------- ---------------- ------------- ------------ ----------
E35/1000/2013 TFT001 COMPLEX ANALYSIS 1 1 71.04
E35/1000/2013 TFT002 LINEAR ALGEBRA 1 1 56.25发布于 2013-10-10 08:26:03
试试这个:
select stu_reg_no, unit_code, exam_unit, exam_semester, student_year,
(select sum(per_centage_score) from student_results_master t2 where t2.exam_unit = t1.exam_unit)
/(select count(per_centage_score) from student_results_master t2 where t2.exam_unit = t1.exam_unit)
from student_results_master t1
group by unit_code, exam_unit, stu_reg_no, exam_semester, student_year;https://stackoverflow.com/questions/19290329
复制相似问题