student(stuno,stuname,sex)学号,姓名,性别
teacher(tno,tname) 教职工号,姓名
course(cno,cname) 课 程号 课程名称
class(classno,classname) 班级号, 班级名称
sc(stuno,cno,grade) 学习 学号 课程号 成绩
这五张表怎样同时查出
stuno, stuname,cno,cname, grade
需要有外键关系才能的
select sc.stuno,sc.cno ,student.stuname,course.cname ,sc.grade from sc,student,course where sc.stuno=student.stuno and sc.cno=course.cno;
一定设好主键,建好外键。然后投影。
select s.stuno, s.stuname,c.cno,c.cname, g.grade from student s,course c,sc g where s.stuno=g.stuno and g.cno=c.cno
根据学号和课程号合并就行,不过teacher和class完全没用啊
多表关联即可:
SELECT t1.stuno,t1.stuname,t2.cno,t3.cname,t2.grade
FROM student t1
inner join sc t2 on t1.stuno=t2.stuno
inner join course t3 on t2.cno=t3.cno;
参考自:mysql join语法及优化 http://www.data.5helpyou.com/article209.html
关联查询,join on啊