how to query percentage of students attendance in table below
Name Attendance
A 1
B 0
B 1
B 1
B 1
B 1
B 1
A 0
A 0
A 0
how to query percentage of students attendance in table below
Name Attendance
A 1
B 0
B 1
B 1
B 1
B 1
B 1
A 0
A 0
A 0
I suggest Sum(Attendance) / Count(Attendance)
as a percentage:
select Name,
Sum(Attendance) / Count(Attendance) * 100 as Percentage
from MyTable
group by Name
So, in case of A
student we have Sum(Attendance) == 1 + 0 + 0 + 0 = 1
and Count(Attemdance) == 4
and the percentage is 1 / 4 * 100 = 25