📅  最后修改于: 2022-03-11 15:05:19.654000             🧑  作者: Mango
Create table tbl_student (
id_tbl_student integer not null primary key autoincrement,
col_student_no text not null unique,
col_name text not null,
col_sex text null,
col_status int null,
col_birthday date null,
col_id_no text null unique,
col_mobile integer UNIQUE
);
create table tbl_course (
id_tbl_course integer not null primary key autoincrement,
col_name text not null unique,
col_hours int null default 64
);
create table tbl_score (
id_tbl_score integer not null primary key autoincrement,
col_score int null check (col_score>=0 and col_score<=100),
id_tbl_course int not null references tbl_course (id_tbl_course),
id_tbl_student int not null references tbl_student (id_tbl_student),
constraint idxu_course_student unique (id_tbl_student, id_tbl_course)
);
insert into tbl_student
values ('SW103101','è¡æ¥','F',1,'1990-5-7','372822199005076102','13987654321');
insert into tbl_student
values ('SW103102','éç³','M',1,'1990-2-20','420922199002201021','13987654322');
insert into tbl_student
values ('SW103103','ç¨æå¤','F',1,'1989-9-29','320283198909296002','13987654323');
insert into tbl_student
values ('SW103109','é 迪','M',1,'1990-5-5','342623199005058001','13987654329');
insert into tbl_student
values ('NW102101','çä¿å³°','M',1,'1989-4-22','362424198904222008','13987654341');
insert into tbl_student
values ('NW102102','çææ','F',1,'1989-4-9','320283198904095017','13987654342');
insert into tbl_course values ('C++ç¨åºè®¾è®¡','80');
insert into tbl_course values ('计ç®æºç½ç»ææ¯','48');
insert into tbl_course values ('æ°æ®åºç¨åºè®¾è®¡','64');
insert into tbl_score values (82,1,1);
insert into tbl_score values (91,1,2);
insert into tbl_score values (86,1,3);
insert into tbl_score values (90,1,4);
insert into tbl_score values (67,1,5);
insert into tbl_score values (66,2,6);
insert into tbl_score values (79,2,1);
insert into tbl_score values (94,2,2);
insert into tbl_score values (87,3,4);
insert into tbl_score values (68,3,5);
select col_name, col_mobile from tbl_student where col_sex like '%f' ;
id_tbl_student of all students whose score is greater than 80.
select id_tbl_student from tbl_score where col_score >79;
name, id_tbl_course, col_score from tbl_student and tbl_score.
select tbl_student.col_name, tbl_score.col_score, tbl_score.id_tbl_student
from tbl_score
INNER JOIN tbl_student on tbl_score.id_tbl_student=tbl_student.id_tbl_student
select tbl_student.col_name, tbl_score.col_score
from tbl_score
INNER JOIN tbl_student on tbl_score.id_tbl_course=1;