Auto commit
This commit is contained in:
parent
049a9c4108
commit
5d520d977f
@ -185,12 +185,12 @@ SELECT st.*, c1.score '01课程', c2.score '02课程'
|
||||
FROM students st, (
|
||||
SELECT sc1.student_id, sc1.score
|
||||
FROM scores sc1
|
||||
WHERE sc1.course_id = 1
|
||||
WHERE sc1.course_id = '01'
|
||||
)c1,
|
||||
(
|
||||
SELECT sc2.student_id, sc2.score
|
||||
FROM scores sc2
|
||||
WHERE sc2.course_id = 2
|
||||
WHERE sc2.course_id = '02'
|
||||
)c2
|
||||
WHERE st.id = c1.student_id AND st.id = c2.student_id AND c1.score > c2.score;
|
||||
|
||||
@ -199,12 +199,12 @@ SELECT st.*, c1.score '01课程', c2.score '02课程'
|
||||
FROM students st, (
|
||||
SELECT sc1.student_id, sc1.score
|
||||
FROM scores sc1
|
||||
WHERE sc1.course_id = 1
|
||||
WHERE sc1.course_id = '01'
|
||||
)c1,
|
||||
(
|
||||
SELECT sc2.student_id, sc2.score
|
||||
FROM scores sc2
|
||||
WHERE sc2.course_id = 2
|
||||
WHERE sc2.course_id = '02'
|
||||
)c2
|
||||
WHERE st.id = c1.student_id AND st.id = c2.student_id;
|
||||
|
||||
@ -215,13 +215,13 @@ LEFT JOIN
|
||||
(
|
||||
SELECT sc1.student_id, sc1.score
|
||||
FROM scores sc1
|
||||
WHERE sc1.course_id = 1
|
||||
WHERE sc1.course_id = '01'
|
||||
)c1 ON st.id = c1.student_id
|
||||
LEFT JOIN
|
||||
(
|
||||
SELECT sc2.student_id, sc2.score
|
||||
FROM scores sc2
|
||||
WHERE sc2.course_id = 2
|
||||
WHERE sc2.course_id = '02'
|
||||
)c2 ON st.id = c2.student_id
|
||||
WHERE c1.score IS NOT NULL;
|
||||
|
||||
@ -232,13 +232,13 @@ LEFT JOIN
|
||||
(
|
||||
SELECT sc1.student_id, sc1.score
|
||||
FROM scores sc1
|
||||
WHERE sc1.course_id = 1
|
||||
WHERE sc1.course_id = '01'
|
||||
)c1 ON st.id = c1.student_id
|
||||
LEFT JOIN
|
||||
(
|
||||
SELECT sc2.student_id, sc2.score
|
||||
FROM scores sc2
|
||||
WHERE sc2.course_id = 2
|
||||
WHERE sc2.course_id = '02'
|
||||
)c2 ON st.id = c2.student_id
|
||||
WHERE c1.score IS NULL AND c2.score IS NOT NULL;
|
||||
|
||||
@ -256,14 +256,72 @@ WHERE students.id IN (
|
||||
SELECT student_id
|
||||
FROM scores
|
||||
);
|
||||
|
||||
#4.查询所有同学的学生编号、学生姓名、选课总数、所有课程的总成绩(没成绩的显示为 null )
|
||||
SELECT st.id, st.`name`, COUNT(*), SUM(sc.score)
|
||||
FROM students st
|
||||
LEFT JOIN scores sc ON st.id = sc.student_id
|
||||
GROUP BY st.id;
|
||||
#4.1查有成绩的学生信息
|
||||
SELECT st.id, st.`name`, COUNT(*), SUM(sc.score)
|
||||
FROM students st
|
||||
LEFT JOIN scores sc ON st.id = sc.student_id
|
||||
WHERE sc.score IS NOT NULL
|
||||
GROUP BY st.id;
|
||||
|
||||
#5.查询「李」姓老师的数量
|
||||
SELECT COUNT(*)
|
||||
FROM teachers t
|
||||
WHERE t.`name` LIKE '李%';
|
||||
|
||||
#6.查询学过「张三」老师授课的同学的信息
|
||||
SELECT st.*
|
||||
FROM students st, scores sc
|
||||
WHERE st.id = sc.student_id AND sc.course_id = (
|
||||
SELECT c.id
|
||||
FROM courses c, teachers t
|
||||
WHERE c.teacher_id = t.id AND t.`name` = '张三'
|
||||
);
|
||||
|
||||
#7.查询没有学全所有课程的同学的信息
|
||||
SELECT st.*
|
||||
FROM students st
|
||||
LEFT JOIN scores sc ON st.id = sc.student_id
|
||||
LEFT JOIN courses c ON sc.course_id = c.id
|
||||
GROUP BY st.id
|
||||
HAVING COUNT(*) < 3;
|
||||
|
||||
#8.查询至少有一门课与学号为" 01 "的同学所学相同的同学的信息
|
||||
SELECT st.*
|
||||
FROM students st, scores sc
|
||||
WHERE st.id = sc.student_id AND sc.course_id IN(
|
||||
SELECT
|
||||
FROM courses
|
||||
WHERE student_id = '01'
|
||||
);
|
||||
|
||||
#9.查询和" 01 "号的同学学习的课程完全相同的其他同学的信息
|
||||
SELECT st.*
|
||||
FROM students st, scores sc
|
||||
WHERE st.id = sc.student_id AND sc.course_id AND st.id <> '01'
|
||||
GROUP BY st.id
|
||||
HAVING GROUP_CONCAT(sc.course_id) = (
|
||||
SELECT GROUP_CONCAT(c.course_id)
|
||||
FROM scores c
|
||||
WHERE c.student_id = '01'
|
||||
);
|
||||
|
||||
#10.查询没学过"张三"老师讲授的任一门课程的学生姓名
|
||||
|
||||
#11.查询两门及其以上不及格课程的同学的学号,姓名及其平均成绩
|
||||
|
||||
#12.检索" 01 "课程分数小于 60,按分数降序排列的学生信息
|
||||
|
||||
#13.按平均成绩从高到低显示所有学生的所有课程的成绩以及平均成绩
|
||||
|
||||
#14.查询各科成绩最高分、最低分和平均分:以如下形式显示:课程 ID,课程 name,最高分,最低分,平均分,及格率,中等率,优良率,优秀率;(及格为>=60,中等为:70-80,优良为:80-90,优秀为:>=90)
|
||||
|
||||
#15.按各科成绩进行排序,并显示排名, Score 重复时保留名次空缺
|
||||
|
||||
#15.1按各科成绩进行排序,并显示排名, Score 重复时合并名次
|
||||
```
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user