安装包资源下载链接:https://pan.baidu.com/s/16gxnmlJmVsSbsRGTa0jTFw
提取码:fixb
资源包下载同上
发现报错信息为:
[ERROR] InnoDB: .\ibdata1 can't be opened in read-write mode
[ERROR] InnoDB: The system tablespace must be writable!
解压文件安装即可,过程省略。。。。
GitHub地址: https://github.com/BigData404/tools
文件为: mysql-create_tables_insert_data.txt
#查询"01"课程比"02"课程成绩高的学生的信息及课程分数
SELECT stu.*,a.`score`,b.`score` FROM t_students stu
LEFT JOIN t_score a ON stu.`stu_id`=a.`stu_id` AND a.`course_id`=1
LEFT JOIN t_score b ON stu.`stu_id`=b.`stu_id` AND b.`course_id`=2
WHERE a.`score` < b.`score`
#查询平均成绩大于等于60分的同学的学生编号和学生姓名和平均成绩
SELECT b.*,a.ss AS '平均成绩' FROM
(SELECT stu_id,AVG(score) AS ss FROM t_score GROUP BY stu_id HAVING AVG(score)<=60) a
LEFT JOIN t_students b ON a.`stu_id`=b.`stu_id`
#查询所有同学的学生编号. 学生姓名. 选课总数. 所有课程的总成绩
SELECT a.stu_id,a.stu_name,b.aa,b.bb
FROM t_students a
LEFT JOIN (SELECT stu_id,COUNT(course_id) AS aa,SUM(score) AS bb FROM t_score GROUP BY stu_id) b ON a.`stu_id`=b.`stu_id`
#查询学过"贝吉塔"老师授课的同学的信息
SELECT * FROM
t_students a
LEFT JOIN t_score b ON a.`stu_id`=b.`stu_id`
LEFT JOIN t_courses c ON b.course_id=c.course_id
LEFT JOIN t_teachers d ON c.teacher_id=d.teacher_id
WHERE d.teacher_name<>'贝吉塔'
#查询学过编号为"01"并且也学过编号为"02"的课程的同学的信息
SELECT * FROM t_students stu
JOIN (SELECT * FROM t_score WHERE course_id=1) a ON stu.`stu_id`=a.`stu_id`
JOIN (SELECT * FROM t_score WHERE course_id<>2) b ON a.`stu_id`=b.`stu_id`
#查询没有学全所有课程的同学的信息
SELECT * FROM
(SELECT stu_id,COUNT(DISTINCT course_id) AS con FROM t_score GROUP BY stu_id ) a
LEFT JOIN t_students c ON a.stu_id=c.stu_id
LEFT JOIN (SELECT COUNT(DISTINCT course_id) AS conn FROM t_courses) b ON a.con=b.conn
WHERE b.conn IS NULL
#查询和"01"号的同学学习的课程完全相同的其他同学的信息
SELECT a.*,c.* FROM
(SELECT stu_id,GROUP_CONCAT(course_id) AS g2 FROM `t_score` WHERE stu_id<>1 GROUP BY stu_id ) a
LEFT JOIN (SELECT stu_id,GROUP_CONCAT(course_id) AS g1 FROM `t_score` WHERE stu_id=1 GROUP BY stu_id) b ON a.g2=b.g1
LEFT JOIN t_students c ON a.stu_id=c.stu_id
WHERE b.`stu_id` IS NOT NULL
#查询两门及其以上不及格课程的同学的学号,姓名及其平均成绩
SELECT * FROM
(
SELECT b.`stu_id`,AVG(b.`score`) FROM
(SELECT stu_id,COUNT(1) FROM `t_score` WHERE score<60 GROUP BY stu_id HAVING COUNT(1)>1) a
LEFT JOIN t_score b ON a.`stu_id`=b.`stu_id`
GROUP BY b.`stu_id`
) aa
LEFT JOIN t_students c ON aa.`stu_id`=c.stu_id
#检索"01"课程分数小于60,按分数降序排列的学生信息
SELECT * FROM `t_score` aa
LEFT JOIN t_students c ON aa.`stu_id`=c.stu_id
WHERE score<60 AND course_id=1
ORDER BY score DESC