创库

create database one20210606 default charset=utf8;

use one20210606;
create table studentinfio(
studentid varchar(10),
studentname varchar(20),
gender varchar(2),
birthday date,
classid int(10),
beginyear varchar(10),
phone varchar(11),
province varchar(20),
city varchar(20),
email varchar(50)

);
create table teacher (
id int,
teachername varchar(10),
hiredate date,
gender char
);

create table classinfo(
id int, # 班级编号
classname varchar(10),
gradeid int, # 年纪编号
beginyear varchar(10) # 开始年份
);

create  table subject(
 id int,
subjectname varchar(10),
teacherid int
);

create  table exam(
id int,
exam int,
subjectid int,
studentid  int,
remark varchar(10) # 备注
);

create  table grade(
 id int,
 gradename varchar(10),
 major  varchar(20)
 );

-- 子查询 用子查询实现,查询出学生“林平之”的同班同学

1找到林平之的班级

2查同班同学

select classid from studentinfo where studentname='林平之';

select *from studentinfo where classid=(select classid from studentinfo where studentname='林平之');

你可能感兴趣的:(创库)