正在回答
助你一力,你要根据课程内容自己动脑呀,参考一下我的sql语句。
select c.name as'班级名称',s.course as'课程',avg(s.mark) as'平均分数' from class c join student stu join score s on c.c_id = stu.class and stu.s_id=s.s_id group by c.c_id,s.course order by c.c_id
SELECT * FROM mysql.user WHERE user='root'\G;
CREATE TABLE IF NOT EXISTS class(
c_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT KEY COMMENT '编号',
name VARCHAR(50) NOT NULL UNIQUE COMMENT '班级',
descrip VARCHAR(50) NOT NULL COMMENT '备注'
);
CREATE TABLE IF NOT EXISTS student(
s_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT KEY COMMENT '编号',
name VARCHAR(50) NOT NULL COMMENT '姓名',
gender ENUM('男','女') NOT NULL DEFAULT '男' COMMENT '性别',
class TINYINT NOT NULL COMMENT '班级'
);
CREATE TABLE IF NOT EXISTS score(
sc_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT KEY COMMENT '编号',
s_id SMALLINT UNSIGNED NOT NULL COMMENT '学生ID',
course VARCHAR(50) NOT NULL COMMENT '课程',
mark TINYINT UNSIGNED NOT NULL COMMENT'分数'
);
--2、查询每个班级中每一科的平均成绩,显示数据包括班级名称,课程以及平均分数,并按照班ID升序排列
SELECT c.name,s.course,AVG(s.mark)
FROM score AS s
JOIN class AS c
JOIN student AS t
on c.c_id=t.s_id and t.s_id=s.s_id
GROUP BY c.c_id,c.name,s.course
;
INSERT class(c_id,name,descrip) VALUES(001,'一年级一班','重点班'),
(002,'一年级二班','重点班'),
(003,'二年级一班','重点班'),
(004,'二年级二班','普通班');
INSERT student(s_id,name,gender,class) VALUES(1001,'赵晓明','男',001),
(1002,'王晓红','女',001),
(1003,'张晓晓','女',001),
(1004,'孙琪琪','女',003),
(1005,'李米米','女',004),
(1006,'赵晓刚','男',003),
(1007,'张大宝','男',002),
(1008,'张兰','女',004),
(1009,'孙好','男',001);
INSERT score(sc_id,s_id,course,mark) VALUES(001,1001,'数学',98),
(002,1001,'语文',90),
(003,1001,'英语',97),
(004,1002,'数学',96),
(005,1002,'语文',88),
(006,1003,'语文',88),
(007,1002,'英文',91),
(008,1003,'数学',96),
(009,1003,'英语',86),
(010,1004,'英语',89),
(011,1004,'英语',82),
(012,1004,'英语',83),
(013,1005,'英语',75),
(014,1005,'英语',86),
(015,1005,'英语',77),
(016,1006,'英语',81),
(017,1006,'英语',77),
(018,1006,'英语',60),
(019,1007,'英语',89),
(020,1007,'英语',56),
(021,1007,'英语',70),
(022,1008,'英语',87),
(023,1008,'英语',55),
(024,1008,'英语',66),
(025,1009,'英语',78),
(026,1009,'英语',60),
(027,1009,'英语',52);
源码贴上 求救
求老师帮助!!!
SELECT c.name,s.course,AVG(s.mark)
FROM score AS s
JOIN class AS c
GROUP BY s.course;
- 参与学习 人
- 提交作业 357 份
- 解答问题 8016 个
本阶段将带你学习MySQL数据库,JDBC接口,MyBatis框架等,带你掌握的数据的存放和管理。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星