MySQL資料庫例題:學生表-課程表-成績表【查詢成績】
阿新 • • 發佈:2019-02-01
- //建立學生表
- mysql> create table student(
- -> sno char(5) not null primary key,
- -> sname char(8) not null,
- -> ssex char(1) check(ssex='1' or ssex='0'),
- -> sage tinyint(2),
- -> sdept varchar(20))charset=utf8;
- //建立課程表
- mysql> create table course(
- -> courseid int not null auto_increment primary key,
- -> cname varchar(16) not null)charset=utf8;
- //建立成績表
- mysql> create table sc (
- -> grade int not null,
- -> sno char(5) not null,
- -> courseid int not null)charset=utf8;
mysql> select student.sname,student.sno,course.cname,sc.grade from student,cours
e,sc where student.sno=sc.sno and course.courseid=sc.courseid;
mysql> select student.sname,student.sno,course.cname,sc.grade from student,cours
e,sc where student.sno=sc.sno and course.courseid=sc.courseid and student.sno='00001';