作业及第4个问题求解
#1查询没学过"张三"老师授课的同学的信息
SELECT
student.S,student.Sname,student.Sage,student.Ssex
FROM
student
LEFT JOIN (
SELECT
student.S
FROM
student
JOIN sc ON student.S = sc.S
JOIN course ON sc.C = course.C
JOIN teacher ON course.T = teacher.T
WHERE
teacher.Tname = “张三”
) AS s1 ON student.S = s1.S
WHERE
s1.S IS NULL;
#2查询课程不及格(小于60分)的学生,课程名,以及对应分数,并先根据学生分组
#group_concat分组
SELECT student.S,student.Sname,GROUP_CONCAT(course.Cname),GROUP_CONCAT(sc.score)
FROM student
LEFT JOIN sc ON student.S=sc.S
LEFT JOIN course ON sc.C=course.C
WHERE sc.score<60
GROUP BY student.S;
#3查询平均成绩大于等于60分的同学的学生编号和学生姓名和平均成绩
SELECT student.S,student.Sname,AVG(sc.score) AS avg
FROM student LEFT JOIN sc ON student.S=sc.S
GROUP BY student.S
HAVING avg>=60;
#4 对于题目三,若是理解为 查询成绩都大于各科成绩的平均分的学生姓名和各科的平均分怎么写
正在回答
同学你好,sql语句完成的不错,很棒呐,第四个问题同学将最后条件改成各科成绩大于平均成绩即可
祝学习愉快~
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星