练习题

1.建库
库名:linux50 字符集:utf8 校验规则:utf8_general_ci

create database linux4 charset utf8 default collate = utf8_general_ci;
表名:student(学生表)
字段 数据类型要求 是否为空 注释
sno 最多20位 否 学号(主键)
sname 可变长 否 学生姓名
sage 最小整数,非负数 否 学生年龄
ssex 0,1 否 学生性别(1是男,0是女)默认为男)
sbirthday 时间类型 默认为空 学生生日
class 可变长 否 学生班级

create table student( sno int(5) zerofill primary key auto_increment comment '学号(主键)', sname varchar(12) not null comment '学生姓名', sage tinyint unsigned not null comment '学生年龄', ssex enum('0','1') not null default '1' comment '学生性别(1是男,0是女)', sbirthday datetime default null comment '学生生日', class varchar(12) not null comment '学生班级'); 表名:course(课程表) | 字段 | 数据类型要求 | 是否为空 | 注释 | | ---- | ------------ | -------- | ---- | 表名:course(课程表) 字段 数据类型要求 是否为空 注释 cno 最多20位 否 课程号(主键) cname 可变长 否 课程名称 tno 可变长 否 教师编号 字段 数据类型要求 是否为空 注释 cno 最多20位 否 课程号(主键) cname 可变长 否 课程名称 tno 可变长 否 教师编号 mysql> create table course( -> cno int(5) not null primary key auto_increment comment '课程号(主键)', -> cname varchar(30) not null comment '课程名称', -> tno varchar(20) not null comment '教师编号'); 表名:score(成绩表) 字段 数据类型要求 是否为空 注释 sno 最多20位 否 学号(主键) cno 最多20位 否 课程号(主键) mark 浮点数(4,1) 否 成绩 create table score( sno int(5) zerofill comment '学号(主键)', cno int(5) comment '课程号(主键)', mark float(4,1) not null comment '成绩', primary key (sno,cno)); 表名:teacher(教师表) 字段 数据类型要求 是否为空 注释 tno 最多20位 否 教师编号(主键) tname 可变长 否 教师姓名 tage 最小整数,非负数 否 教师年龄 tsex 0,1 否 教师性别(1是男,0是女)默认为男) prof 可变长 是 教师职称 depart 可变长 否 教师部门 mysql> create table teacher( -> tno int(5) not null primary key auto_increment comment '教师编号', -> tname varchar(12) not null comment '教师姓名', -> tage tinyint unsigned not null comment '教师年龄', -> tsex enum('0','1') not null default '1' comment '教师性别', -> prof varchar(12) comment '教师职称', -> depart varchar(12) not null comment '教师部门'); 插入数据练习: 1.将自己班级小组所有人员信息插入到student表中(数据自定义) insert into student(sname,sage,ssex,class) values('陈浩',26,'1','6'),('杨孝义',18,'1','6'),('姚成龙',52,'1','6'),('强哥',5,'1','6'),('崔帅',21,'1','6'),('mysql鬼才',8,'0','6'); 2.将曾导、徐导、李导信息插入教师表中(数据自定义) insert into teacher(tname,tage,tsex,prof,depart) values('曾导',18,'1','教导主任','语言系'),('徐导',84,'0','僵尸','文学系'),('李导',73,'0','助教','科学系'); 3.将数学、语文、英语学科插入到课程表中(数据自定义) insert into course(cname,tno) values('数学','001'),('语文','002'),('英语','003'); 4.将分数插入到成绩表中(数据自定义) insert into score(sno,cno,mark) values(1,1,90.0),(2,1,10.0),(3,1,60.0),(1,2,90.0),(2,2,99.5),(3,2,80.0),(1,3,80.5),(2,3,60.0),(3,3,88.0); 查询练习: 1.查询student表中的所有记录的sname、ssex和class列。 select sname,ssex,class from student; 2.查询教师所有的单位即不重复的depart列。 select distinct(depart) from teacher; 3.查询student表的所有记录。 select * from student; 4.查询score表中成绩在60到80之间的所有记录。 select * from score where mark>60 and mark<80; 5.查询score表中成绩为85,86或88的记录。 select * from score where mark=85 or mark=86 or mark=88; select * from score where mark in (85,86,88); 6.查询student表中1班或性别为“女”的同学记录。 select * from student where class="1" or ssex='0'; 7.以class降序查询Student表的所有记录。 select * from student order by class desc; 8.以cno升序、mark降序查询Score表的所有记录 select * from score order by mark desc,cno asc; 9.查询2班的学生人数。 select count(*) from student where class="6"; 10.查询”曾志高翔“教师任课的学生成绩。 select teacher.tname,student.sname,score.mark,course.cname from teacher,student,score,course where teacher.tno=course.tno and student.sno=score.sno and score.cno=course.cno and teacher.tname='曾导'; 11.查询语文课程所有男生的成绩并且查出对应课程的教师名,职称,及所在部门。 select course.cname,student.sname,score.mark,teacher.tname,teacher.prof,teacher.depart from course,student,teacher,score where teacher.tno=course.tno and student.sno=score.sno and score.cno=course.cno and student.ssex='1' and course.cname='语文'; 12.把11题查出的成绩按照降序排序。 select course.cname,student.sname,score.mark,teacher.tname,teacher.prof,teacher.depart from course,student,teacher,score where teacher.tno=course.tno and student.sno=score.sno and score.cno=course.cno and student.ssex='1' and course.cname='语文' order by score.mark desc;
posted @ 2019-11-06 20:55  lianbingrong  阅读(167)  评论(0编辑  收藏  举报