现有三个表,学生表 t_student{id,name,age}
成绩表 t_score{id,studentid,score,courseid}
课程表 t_course{id,coursename}
写出,查询所有学生成绩小于60,并且课程名称包含“科目1”的学生信息。
用SQL Server。急求。。
SQL
------解决方案--------------------
select * from t_student,t_score,t_course where score<60 and coursename='科目一'
------解决方案--------------------
select * from t_student stu
left outer join t_score sco on sco.studentid=stu.id and sco.score<60
left outer join t_course?cou on sco.courseid = cou.id and cou.coursename='科目1'
------解决方案--------------------
select * from t_student where id in
(select id from t_score where score<60 and courseid in
(select id from t_course where coursename='科目1'))
------解决方案--------------------
看看4L的符合要求不?
课程表 t_course{id,coursename}
不是:课程表 t_course{courseid,coursename}的话。。
如果是下面的,sql最后一个id改下,改成courseid:
select * from t_student where id in
(select id from t_score where score<60 and courseid in
(select courseid from t_course where coursename='科目1'))