表说明:
class:课程名称,member:学生姓名,add_time:考试时间
`student`表存储了不同学生不同课程的考试记录
针对同一课程,每个学生可以考多次
| exam | ----------------------------------------- | id | class | member | add_time | ----------------------------------------- | 1 | python | judy | 2023-05-15 | ----------------------------------------- | 3 | java | judy | 2023-05-15 | ----------------------------------------- | 7 | python | judy | 2023-06-15 | ----------------------------------------- | 9 | python | lily | 2023-06-15 | ----------------------------------------- idx_class_member (class, member)
获取每一门课程下所有的学生数(每个学生只统计一次)
EXPLAIN select count(*) from `exam` where class =’python ‘ GROUP BY member ;
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+—-+————-+——————–+——-+——————–+——————–+———+——+——-+———————————————————–+
| 1 | SIMPLE | exam| index | idx_class_member | idx_class_member | 40 | NULL | 64684 | Using where; Using index; Using temporary; Using filesort |