设计了3张表,学生、课程、分数,其中数据如图:
(资料图)
获取名字包含‘ma’的学生信息
SELECT * FROM student WHERENAME LIKE '%ma%';
查询‘老马’教的课程所有成绩
SELECT * FROM score where class_id=(SELECT id FROM class where teacher_name= '老马');
查询不及格课程最多的同学信息
SELECT * from student where id=(SELECT student_id,count(*) AS c from score WHERE score<60 group by student_id ORDER BY c DESC LIMIT 1);
查询和mary同性别的其他同学的信息
获取各科成绩最高值/平均值
SELECT class_id,max(score),AVG(score) FROM score GROUP BY class_id ORDER BY class_id;
将课程名是‘数学’,分数不及格但大于50分的同学分数设置为60
获取数学成绩最高的学生信息