student表有如下字段 id stu name, sex, grade
course表有如下字段 id, stu id, course name
写一条sql语句,统计一下每门课程选修的男学生和女学生的人数
写一条sql语句,查找一下每个年级选修人数少于5人的课程
每门课程选修的男学生和女学生的人数,以 sex 分组统计即可
select sex ,count(*) from student,course
where student.id = course.stu_id
group by sex
每个年级选修人数少于5人的课程,以年级和课程 id 分组统计:
select grade, course.id , count(*) as total from student,course
where student.id = course.stu_id
group by grade, course.id
having count(*) < 5