学生管理系统数据库模块
建立数据表
数据表: 年级表(grade):年级 id(主键-gradeid),年级名称(gname)
成绩表(score):id(主键-scoreid),学员编号(stuno),科目 id(subjectid),分数(score),考试时间(examtime)
学生表(student):学生编号(主键-stuid),学生姓名(stuname),登录密码(password),性别(sex),年级 id(gid),电话(telphone),地址(address),出生日期(birthday),邮箱(email)
科目表(subject):科目 id(主键-subjectid),科目名称(subjectname),学时(studycount),年级 id(gradeid)
详细信息
ERROR
通过查询信息显示我们数据表中是否添加成功,但是发现subject中的并没有完成,通过查看提示信息发现我们的varchar设置小了,需要重新设置。
之后,我们再重新更改字段,发现数据存储成功。
注意:在一般情况下,无特殊要求 ,不要随意更改表结构。
数据库练习
1.grade 表增加一个阶段,“就业期”
INSERT INTO `grade` VALUES (4, '就业期');
2.将第三阶段的学生的 gradeid 改为就业期的 id
update student set gid=4 where gid=3;
3.查询所有得了 100 分的学号
select stuno from score where score = 100;
4.查询所有 1989 年出生的学生(1989-1-1~1990-1-1)
select *from student where brithday > '1989-1-1' and brithday < '1990-1-1';
注意date数据得加上引号
5.查询学生姓名为“金蝶”的全部信息
select *from student where stuname='金蝶';
6.查询 subjectid 为 8 的科目考试未及格(60 分)的学号和成绩
select subjectid = 8,stuno,score from score where score<60;
此图说明有未及格的同学,但没有严重到挂8门的同学。
7.查询第 3 阶段课时大于 50 的课程全部信息
select *from subject where gradeid = 3 and studycount > 50;
8.查询 S1101001 学生的考试信息
9.查询所有第二阶段的女生信息新职课教研教学中心
select *from student where gid=2 and sex = '女';
10.“基于.NET 平台的软件系统分层开发”需要多少课时
我们发现这种查询没有统计到总体,需要用到sum。
select sum(studycount) from subject where subjectname='基于.NET 平台的软件系统分层开发';
11.查询“设计 MySchool 数据库”和“面向对象程序设计”的课时(使用 in)
select subjectname,studycount from subject where subjectname in( '设计 MySchool 数据库','面向对象程序设计');
12 .查询所有地址在山东的学生信息
select *from student where address = '山东';
13 .查询所有姓凌的单名同学
select *from student where stuname like'凌_';
单名同学说明只需用到下划线即可,所有名字的话就要用到%适配了。
14.查询 gradeid 为 1 的学生信息,按出生日期升序排序
select *from student where gid = 1 order by brithday;
默认Asc升序,降序desc
15.查询 subjectid 为 3 的考试的成绩信息,用降序排序
select *from score where subjectid = 3 order by score desc;
16.查询 gradeid 为 2 的课程中课时最多的课程信息
select max(studycount) from subject where gradeid = 2;
17.查询北京的学生有多少个
select count(*) from student where address = '北京';
18.查询有多少个科目学时小于50
select count(*) from subject where studycount<50;
通过分组,我们可以更直观观察数据的信息
19.查询 gradeid 为 2 的阶段总课时是多少
select sum(studycount) from subject where gradeid = 2;
20.查询 subjectid 为 2的课程学生平均分
select avg(score) from score where subjectid = 2;
21.查询 gradeid 为 3 的课程中最多的学时和最少的学时
select max(studycount),min(studycount) from subject where gradeid = 3;
22.查询每个科目有多少人次考试
select subjectid,count(subjectid) from score group by subjectid;
23.每个阶段课程的平均课时
select gradeid,avg(studycount) from subject group by gradeid;
24.查询每个阶段的男生和女生个数(group by 两列)
select gid,sex,count(gid)from student group by gid,sex;