Auto commit

This commit is contained in:
smallkun 2025-02-25 09:51:43 +08:00
parent 10a4acf101
commit d44aeed220

View File

@ -332,9 +332,33 @@ FROM scores sc, students st
WHERE sc.course_id = '01' AND sc.score < 60 AND sc.student_id = st.id
ORDER BY sc.score DESC;
#13.按平均成绩从高到低显示所有学生的所有课程的成绩以及平均成绩
#13.按平均成绩从高到低显示所有学生的所有课程的平均成绩
SELECT c.`name`, AVG(sc.score)
FROM scores sc, courses c
WHERE sc.course_id = c.id
GROUP BY c.id
ORDER BY AVG(sc.score) DESC;
#14.查询各科成绩最高分、最低分和平均分:以如下形式显示:课程 ID课程 name最高分最低分平均分及格率中等率优良率优秀率及格为>=60中等为70-80优良为80-90优秀为>=90
SELECT c.id '课程ID', c.`name` '课程名称', MAX(s.score) '最高分', MIN(s.score) '最低分', ROUND(AVG(s.score), 1) '平均值'
FROM scores s, courses c
WHERE s.course_id = c.id
GROUP BY c.id;
SELECT s.course_id,
CONCAT(TRUNCATE(COUNT(IF(s.score >=60, TRUE, NULL))/sc.count*100,2), '%') s1,
CONCAT(TRUNCATE(COUNT(IF(s.score >=70 AND s.score < 80, TRUE, NULL))/sc.count*100,2), '%') s2,
CONCAT(TRUNCATE(COUNT(IF(s.score >=80 AND s.score < 90, TRUE, NULL))/sc.count*100,2), '%') s3,
CONCAT(TRUNCATE(COUNT(IF(s.score >=90, TRUE, NULL))/sc.count*100,2), '%') s4
FROM scores s, (
SELECT course_id, COUNT(*) count
FROM scores
GROUP BY course_id
) sc
WHERE s.course_id = sc.course_id
GROUP BY s.course_id;
#15.按各科成绩进行排序,并显示排名, Score 重复时保留名次空缺