综合练习
Posted chriszun
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了综合练习相关的知识,希望对你有一定的参考价值。
设计表
表关系: 下面每个表的第一个字段是主键,未建立外键,使用逻辑外键
班级表
DROP TABLE IF EXISTS `
class
`;
CREATE TABLE `
class
` (
`cid`
int
(
11
) NOT NULL AUTO_INCREMENT,
`caption` varchar(
255
) NOT NULL,
`grade_id`
int
(
11
) NOT NULL,
PRIMARY KEY (`cid`)
) ENGINE
=
InnoDB AUTO_INCREMENT
=
16
DEFAULT CHARSET
=
utf8;
年级表
DROP TABLE IF EXISTS `class_grade`;
CREATE TABLE `class_grade` (
`gid`
int
(
11
) NOT NULL AUTO_INCREMENT,
`gname` varchar(
255
) NOT NULL,
PRIMARY KEY (`gid`)
) ENGINE
=
InnoDB AUTO_INCREMENT
=
7
DEFAULT CHARSET
=
utf8;
课程表
DROP TABLE IF EXISTS `course`;
CREATE TABLE `course` (
`cid`
int
(
11
) NOT NULL,
`cname` varchar(
255
) NOT NULL,
`teacher_id`
int
(
11
) NOT NULL,
PRIMARY KEY (`cid`)
) ENGINE
=
InnoDB DEFAULT CHARSET
=
utf8;
成绩表
DROP TABLE IF EXISTS `score`;
CREATE TABLE `score` (
`sid`
int
(
11
) NOT NULL AUTO_INCREMENT,
`student_id`
int
(
11
) NOT NULL,
`course_id`
int
(
11
) NOT NULL,
`score` varchar(
255
) DEFAULT NULL,
PRIMARY KEY (`sid`)
) ENGINE
=
InnoDB AUTO_INCREMENT
=
20
DEFAULT CHARSET
=
utf8;
学生表
DROP TABLE IF EXISTS `student`;
CREATE TABLE `student` (
`sid`
int
(
11
) NOT NULL AUTO_INCREMENT,
`sname` varchar(
255
) NOT NULL,
`gender` enum(
‘女‘
,
‘男‘
) NOT NULL DEFAULT
‘男‘
,
`class_id`
int
(
11
) NOT NULL,
PRIMARY KEY (`sid`)
) ENGINE
=
InnoDB AUTO_INCREMENT
=
17
DEFAULT CHARSET
=
utf8;
老师表
DROP TABLE IF EXISTS `teacher`;
CREATE TABLE `teacher` (
`tid`
int
(
11
) NOT NULL,
`tname` varchar(
255
) DEFAULT NULL,
PRIMARY KEY (`tid`)
) ENGINE
=
InnoDB DEFAULT CHARSET
=
utf8;
班级任职表
DROP TABLE IF EXISTS `teacher2cls`;
CREATE TABLE `teacher2cls` (
`tcid`
int
(
11
) NOT NULL AUTO_INCREMENT,
`tid`
int
(
11
) NOT NULL,
`cid`
int
(
11
) NOT NULL,
PRIMARY KEY (`tcid`)
) ENGINE
=
InnoDB AUTO_INCREMENT
=
8
DEFAULT CHARSET
=
utf8;
练习题
1.查询“生物”课程和“物理”课程成绩都及格的学生id和姓名;
2.查询每个年级的班级数,取出班级数最多的前三个年级;
3.查询每位学生的学号,姓名,选课数,平均成绩;
4.查询每个年级的学生人数;
以上是关于综合练习的主要内容,如果未能解决你的问题,请参考以下文章