我有一个表“tbl_student_daily_attendance”如下
daily_id|stud_id|status
1 |1 |0
2 |1 |1
3 |1 |0
4 |1 |1
5 |2 |1
6 |2 |1
7 |2 |0
8 |2 |1
状态列代表存在和缺席,分别为 1 和 0。
我想要的输出是具有最大存在值的stud_id(即status=1)
在上述情况下,它应该返回stud_id = 2
最佳答案
您可以使用如下所示的子查询
select stud_id
from
tbl_student_daily_attendance
group by stud_id
having sum(status) =
( select max(s) from
(select sum(status) s,
stud_id
from tbl_student_daily_attendance
group by stud_id
) t1
)
关于mysql - 如何从出勤表中获取出勤率最高的student_id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52558745/