登录数据库,并创建数据库student
创建数据库命令
create database student
创建两个表student
,和score
即学生表和成绩表。student
表的字段有id
,name
,class
,number
score
表中的字段有number
,chinese
,math
,english
创建表
create table student(`id` int(4),`name` char(40),`class` char(40),`number` char(40));
create table score(`number` char(40),`chinaese` char(40),`math` char(40),`english` char(40));
当前的表
写入测试数据
insert into student(id,name,class,number) values('1',"张三","一班","201901");
insert into student(id,name,class,number) values('2',"令狐冲","二班","201902");
insert into student(id,name,class,number) values('3',"张三丰","三班","201903");
insert into student(id,name,class,number) values('4',"娜可露露","一班","201904");
insert into score(number,chinaese,math,english) values('201901',"90","87","120");
insert into score(number,chinaese,math,english) values('201902',"82","76","96");
insert into score(number,chinaese,math,english) values('201903',"67","82","110");
insert into score(number,chinaese,math,english) values('201904',"23","66","134");
查询如下:
SELECT name, class,chinaese, math, english FROM score a INNER JOIN student b ON a.number = b.number;
这样就将两张表连接到了一起