student和score表mysql语句

student和score表mysql语句_第1张图片
score表
student和score表mysql语句_第2张图片
student表
– 从student表中查询年龄18~22岁的学生信息
SELECT * FROM student WHERE 2017-birth BETWEEN 18 AND 22;

– 从student表中查询每个院系有多少人
SELECT department,COUNT(*) FROM student GROUP BY department

– 计算每个学生的总成绩
SELECT SUM(grade), name FROM student s LEFT JOIN score sc on s.id =sc.stu_id GROUP BY s.id

– 计算每个考试科目的平均成绩
SELECT c_name,AVG(grade) c_name FROM score GROUP BY c_name

– 同时参与计算机和英语考试的学生信息
SELECT * FROM student WHERE id = ANY( SELECT stu_id FROM score WHERE stu_id IN (SELECT stu_id FROM score WHERE c_name= ‘计算机’)AND c_name= ‘英语’ );

– 计算机考试成绩按高到低进行排序
SELECT stu_id FROM score sc WHERE c_name = ‘计算机’ ORDER BY grade DESC

你可能感兴趣的:(mysql)