0
的百分比,我有以下表格:MySQL的 - 計算平均值
平均
id
subject_id
student_id
value
semester_id
classes_students
id
class_academic_year_id
student_id
classes_academic_years
個id
class_id
academic_year_id
學期
id
name
academic_year_id
start_date
end_date
我需要一個查詢,找出從某一類學生的畢業率一學年的某個對象(即平均數高於5的那些人的百分比;例如假設學生的semester_id = 1的平均值爲6,semester_id = 2的平均值爲7,平均值的平均值爲6.5)。
這是當前查詢,但它只返回student_id和兩個學期的平均值。
select averages.student_id, avg(value) from averages
inner join semesters on semesters.id = averages.semester_id
inner join academic_years on academic_years.id = semesters.academic_year_id
inner join classes_students on classes_students.student_id = averages.student_id
inner join classes_academic_years on classes_academic_years.id = classes_students.class_academic_year_id
where averages.subject_id = '66'
and academic_years.id = 3
and classes_academic_years.academic_year_id = academic_years.id
and classes_academic_years.class_id = 259
group by averages.student_id
我想結果是類似於74.5%。有沒有辦法做到這一點?