SQL 查询统计次数及统计次数大于2的记录

649人浏览 / 0人评论

select count(*) as repeat_count,name from “数据表” group by name having repeat_count > 2;

查询学生人数大于10的班级,class_student 为班级和学生中间表

select class_id,count(student_id) student_count from class_student group by class_id having student_count > 10;

 

统计每个班级的人数,按人数数量倒序排序

select class_id,count(student_id) student_count from class_student group by class_id order by student_count desc;

全部评论