select * from 表1 inner join 表2 on 关联条件
select * from 表1 left outer join 表2 on 关联条件
select * from 表1 right outer join 表2 on 关联条件
select * from 表1 cross join 表2 on 关联条件
MYSQL查询
SELECT s.id,AVG(sc.score) FROM student s,studentcourse sc WHERE s.id=sc.student_id GROUP BY s.id HAVING AVG(sc.score)>70
查询所有同学的学号、姓名、选课数、总成绩
SELECT id,NAME
FROM student
WHERE id NOT IN (SELECT student_id
FROM studentcourse
WHERE course_id IN (SELECT course.id
FROM teacher,course
WHERE teacher.id=course.teacher_id
AND teacher.name=’关羽’))
查询学生信息和平均成绩
SELECT s.id,s.name,s.city,s.age, c.name,sc.score,t.name
FROM student s,studentcourse sc,course c,teacher t
WHERE s.id=sc.student_id AND c.id=sc.course_id AND c.teacher_id=t.id GROUP BY s.id
你这个关键是缺个三表的关联字段等于说要建立另外一个表,例如d(id,人)
然后,a,b,c三个表的id都是这个d表的id
这样你这几个表就
select *
from d left jon a on d.id=a.id
xxxxx
这样就能关联起来了
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)