MySQL数据库例题:学生表-课程表-成绩表【查询成绩】

版权声明:本文为BUG先生原创文章,可任意转载,愿请附上本文链接,谢谢。 https://blog.csdn.net/Edogawa_Konan/article/details/81505756

  1. //建立学生表  
  2. mysql> create table student(  
  3.     -> sno char(5) not null primary key,  
  4.     -> sname char(8) not null,  
  5.     -> ssex char(1) check(ssex='1' or ssex='0'),  
  6.     -> sage tinyint(2),  
  7.     -> sdept varchar(20))charset=utf8;  
  8.   
  9. //建立课程表  
  10. mysql> create table course(  
  11.     -> courseid int not null auto_increment primary key,  
  12.     -> cname varchar(16) not null)charset=utf8;  
  13.   
  14. //建立成绩表  
  15. mysql> create table sc (  
  16.     -> grade int not null,  
  17.     -> sno char(5) not null,  
  18.     -> 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';

 

猜你喜欢

转载自blog.csdn.net/Edogawa_Konan/article/details/81505756