1、统计每门课的平均分。2、找出平均分高于90的课程编好。3、统计学时超过60的课程数。4、找出班级人数在3人以下的班级及对应的人数。5、统计每门课不及格的人数,并将2个以上的不及格的课程及不及格人数显示出来。(mysql)
时间: 2023-06-20 08:07:28 浏览: 146
1、统计每门课的平均分。
```
SELECT course, AVG(score) AS avg_score FROM scores GROUP BY course;
```
2、找出平均分高于90的课程编好。
```
SELECT course FROM scores GROUP BY course HAVING AVG(score) > 90;
```
3、统计学时超过60的课程数。
```
SELECT COUNT(*) FROM courses WHERE hours > 60;
```
4、找出班级人数在3人以下的班级及对应的人数。
```
SELECT class, COUNT(*) AS num_students FROM students GROUP BY class HAVING COUNT(*) <= 3;
```
5、统计每门课不及格的人数,并将2个以上的不及格的课程及不及格人数显示出来。
```
SELECT student_id, COUNT(*) AS num_fails FROM scores WHERE score < 60 GROUP BY student_id HAVING COUNT(*) >= 2;
```
阅读全文