MySQL多表的查詢
阿新 • • 發佈:2020-10-13
MySQL多表查詢
1、建立student表和score表
建立student表:
create table student (
id int(10) not null unique primary key,
name varchar(20) not null ,
sex varchar(4) ,
birth year,
department varchar(20) ,
address varchar(50));
建立score表:
create table score (
id int(10) not null unique primary key auto_increment,
stu_id int(10) not null ,
grade int(10));
2、為student表和score表增加記錄
向student表插入記錄的INSERT語句如下:
insert into student values( 901,‘張老大’, ‘男’,1985,‘計算機系’, ‘北京市海淀區’);
insert into student values( 902,‘張老二’, ‘男’,1986,‘中文系’, ‘北京市昌平區’);
insert into student values( 903,‘張三’, ‘女’,1990,‘中文系’, ‘湖南省永州市’);
insert into student values( 904,‘李四’, ‘男’,1990,‘英語系’, ‘遼寧省阜新市’);
insert into student values( 906,‘王六’, ‘男’,1988,‘計算機系’, ‘湖南省衡陽市’);
向score表插入記錄的INSERT語句如下:
insert into score values(NULL,901, ‘計算機’,98);
insert into score values(NULL,901, ‘英語’, 80);
insert into score values(NULL,902, ‘計算機’,65);
insert into score values(NULL,902, ‘中文’,88);
insert into score values(NULL,904, ‘計算機’,70);
insert into score values(NULL,904, ‘英語’,92);
insert into score values(NULL,905, ‘英語’,94);
insert into score values(NULL,906, ‘計算機’,90);
insert into score values(NULL,906, ‘英語’,85);