登录数据库,并创建数据库student
001.jpg
创建数据库命令

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));

002.jpg

当前的表
003.jpg
写入测试数据

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");

004.jpg

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");

查询如下:
005.jpg

SELECT  name, class,chinaese, math, english FROM score a INNER JOIN student b ON a.number = b.number;

这样就将两张表连接到了一起
006.jpg

Last modification:May 5th, 2019 at 09:50 pm
正在沿街乞讨中……