1、第三次作业
01、SELECT * FROM student;
SELECT * FROM score;
02、SELECT * FROM student LIMIT 1, 3;
03、SELECT * FROM student WHERE department IN ('计算机系', '英语系');
04、SELECT * FROM student WHERE birth_year > 1998;
05、SELECT department, COUNT(*) as count FROM student GROUP BY department;
06、SELECT c_name, MAX(grade) AS max_grade FROM score GROUP BY c_name;
07、SELECT c_name, grade FROM score WHERE stu_id = 903;
08、SELECT s.*, sc.* FROM student s JOIN score sc ON s.id = sc.stu_id;
09、SELECT s.id, s.name, SUM(sc.grade) AS total_grade FROM student s JOIN score sc ON s.id = sc.stu_id GROUP BY s.id, s.name;
10、SELECT c_name, AVG(grade) AS avg_grade FROM score GROUP BY c_name;
11、SELECT s.*, sc.grade FROM student s JOIN score sc ON s.id = sc.stu_id WHERE sc.c_name = '计算机' AND sc.grade < 95;
12、SELECT s.*, sc.c_name, sc.grade FROM student s JOIN score sc ON s.id = sc.stu_id WHERE sc.c_name = '计算机' ORDER BY sc.grade DESC;
13、SELECT id FROM student UNION SELECT DISTINCT stu_id FROM score;
14、SELECT s.name, s.department, sc.c_name, sc.grade FROM student s JOIN score sc ON s.id = sc.stu_id WHERE s.name LIKE '张%' OR s.name LIKE '王%';
15、SELECT s.name, YEAR(CURDATE()) - s.birth_year AS age, s.department, sc.c_name, sc.grade FROM student s JOIN score sc ON s.id = sc.stu_id WHERE s.address LIKE '%湖南省%';