数据库
首页 > 数据库> > 数据库练习题

数据库练习题

作者:互联网

数据库练习题:

数据表:
 年级表(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

 

 

1. grade 表增加一个阶段,“就业期”    
insert into grade(gradeid,gname)values(1,'就业期');
2.在学生表中将第三阶段的学生的 gradeid 改为就业期的 id
update student set gid=(select gradeid from grade where gname='就业期')
where gid=(select gardeid from grade where gname='第三阶段');
3.查询所有得了 100 分的学号
select stuno from score where score=100;
4.查询所有 1989 年出生的学生(1989-1-1~1990-1-1)
select * from student where birthday between '1989-1-1' and '1989-12-31';
5.查询学生姓名为“金蝶”的全部信息
selcet * from student where stuname='金蝶';
#多表连接查询
selcet *from student s,grade g,score c,subject j
where
s.gid=g.gradeid  and   c.stuno=s.stuid  and  j.gradeid=g.gradeid
and stuname='金蝶';
6.查询 subject id 为 8 的科目考试未及格(60 分)的学号和成绩
select stuno,score from score where subjectid=8 and score<60;
7.查询第 3 阶段课时大于 50 的课程全部信息
select * from subject where gradeid=(selcet gradeid from grade where gname='第三阶段') and studycount>50; 
8.查询 S1101001 学生的考试信息
select * from score where stuno='S1101001';
9.查询所有第二阶段的女生信息
select * from student where sex='女' and gid=(selcet gradeid from grade where gname='第二阶段');
10.“基于.NET 平台的软件系统分层开发”需要多少课时
select studycount from subject where subjectname='基于.NET 平台的软件系统分层开发';
11.查询“设计 MySchool 数据库”和“面向对象程序设计”的课时(使用 in)
select studycount from subject where subjectname in('设计 MySchool 数据库','面向对象程序设计');
12 查询所有地址在山东的学生信息
select * from studnet where address like '%山东%';
13 查询所有姓凌的单名同学
select * from student where stuname like '凌_';
14.查询 gradeid 为 1 的学生信息,按出生日期升序排序
select * from student where stuname=1 order by birthday;
15.查询 subject id 为 3 的考试的成绩信息,用降序排序
select *from score where subject=3 order by score desc;
16.查询 gradeid 为 2 的课程中课时最多的课程信息
select * from  subject where gradeid=2 order by studentcount desc limit 0,1;
17.查询北京的学生有多少个
select count(*) from studnt where address like '%北京%';
18.查询有多少个科目学时小于 50
select count(*) from subject where studycount<50;
19.查询 gradeid 为 2 的阶段总课时是多少
select sum(studycount) frrom subject where gradeid=2;
20.查询 subjectid 为 8 的课程学生平均分
select avg(score) from score where subject=8;
21.查询 gradeid 为 3 的课程中最多的学时和最少的学时
select  max(studycount),min(studycount) from subject  where gardeid=3;
22.查询每个科目有多少人次考试
select subjectid,count(*) from score 
group by subjectid;
#多表关联查询
select subjectname,count(*) form score,subject where score.subjectid=subject.subjectid
group by subjectname;
23.每个阶段课程的平均课时
select gardeid,avg(studycount) from subject
group by gradeid ;
#年级名称和学时的关联关系
select gname,avg(studycount) from subject,garde where subject.gradeid=garde.gardeid
group by gname;
24.查询每个阶段的男生和女生个数(group by 两列)
#sclect sex,count(*) from studnet where sex='男';
select gid,sex,count(*) from student 
group by gid,sex;
 

标签:练习题,gradeid,数据库,查询,score,where,select,subject
来源: https://blog.csdn.net/weixin_44722237/article/details/117322789