学生表student(sid,sname,sage,ssex),
sid学生编号,sname学生姓名,sage学生年龄,ssex学生性别
创建表sql
create table student(sid char(4) not null,sname varchar(20) not null,sage int(3) not null,ssex char(4) not null,primary key(sid));
插入数据:
insert into student values(‘s001‘,‘张三 ‘,‘16‘,‘男‘),(‘s002‘,‘王五 ‘,‘15‘,‘男‘),(‘s003‘,‘张三 ‘,‘16‘,‘女‘); insert into student values(‘s001‘,‘zhangsan ‘,‘16‘,‘nan‘),(‘s002‘,‘wangwu ‘,‘15‘,‘nan‘),(‘s003‘,‘zhuli‘,‘16‘,‘nv‘);
sid | sname | sage | ssex |
s001 | 张三 | 16 | 男 |
s002 | 王五 | 15 | 男 |
s003 | 朱莉 | 16 | 女 |
课程表course(cid,cname,tid)
cid课程编号,cname课程名称,tid教师编号
创建表sql
create table course(cid char(4) not null,cname varchar(20) not null, primary key(cid));
插入数据:
insert into course values(‘c001‘,‘语文‘),(‘c002‘,‘数学‘),(‘c003‘,‘英语‘); insert into course values(‘c001‘,‘chinese‘),(‘c002‘,‘maths‘),(‘c003‘,‘english‘);
cid | cname |
c001 | 语文 |
c002 | 数学 |
c003 | 英语 |
教师表teacher(tid,tname,cid)
tid教师编号,tname教师名称,cid课程编号
sql:
create table teacher(tid char(4) not null,tname varchar(20) not null, cid char(4) not null,primary key(tid),foreign key(cid) references course(cid));
插入数据:
insert into teacher values(‘t001‘,‘王刚‘,‘c001‘),(‘t002‘,‘华罗庚‘,‘c002‘),(‘t003‘,‘刘怡‘,‘c003‘); insert into teacher values(‘t001‘,‘wanggang‘,‘c001‘),(‘t002‘,‘hualuogen‘,‘c002‘),(‘t003‘,‘liuyi‘,‘c003‘);
tid | tname | cid |
t001 | 王刚 | coo1 |
t002 | 华罗庚 | c002 |
too3 | 刘怡 | c003 |
成绩表score(id,sid,cid,score)
id成绩编号,sid学生编号,cid课程编号,score成绩
sql:
create table score(id char(4) not null,sid char(4) not null,cid char(4) not null,score int(3) not null,primary key(id),foreign key(sid) references student(sid),foreign key(cid) references course(cid));
插入数据:
insert into score values(‘001‘,‘s002‘,‘c001‘,80),(‘002‘,‘s001‘,‘c001‘,77),(‘003‘,‘s002‘,‘c002‘,85),(‘004‘,‘s003‘,‘c001‘,50),(‘005‘,‘s001‘,‘c003‘,82),(‘006‘,‘s002‘,‘c003‘,79),(‘007‘,‘s001‘,‘c002‘,90),(‘008‘,‘s003‘,‘c002‘,76),(‘009‘,‘s003‘,‘c003‘,79);
id | sid | cid | score |
001 | s002 | c001 | 80 |
002 | s001 | c001 | 77 |
003 | s002 | c002 | 85 |
004 | s003 | c001 | 50 |
005 | s001 | c003 | 82 |
006 | s002 | c003 | 79 |
007 | s001 | c002 | 90 |
008 | s003 | c002 | 76 |
009 | s003 | c003 | 79 |
题目一:求语文比数学成绩高的学生
题目二:求大于平均分大于75的学生
题目三