如何查询下表中的学生出勤率百分比
Name Attendance
A 1
B 0
B 1
B 1
B 1
B 1
B 1
A 0
A 0
A 0
答案 0 :(得分:0)
我建议Sum(Attendance) / Count(Attendance)
为百分比:
select Name,
Sum(Attendance) / Count(Attendance) * 100 as Percentage
from MyTable
group by Name
因此,对于A
学生,我们有Sum(Attendance) == 1 + 0 + 0 + 0 = 1
和Count(Attemdance) == 4
,且百分比为1 / 4 * 100 = 25