日期:2014-05-16 浏览次数:20481 次
Student:
Score
1.查询年龄超过20岁的姓名\年龄\所在班级
select
sName,
sAge,
cName
from Student as TS
inner join Class TC
on TC.clsId=TS.sClassId
where sAge>20
------------------------------------------------
2.查询出所有参加考试的同学的学生编号,姓名,考试成绩。
select
sId,
sName,
english,
math
from Student
inner join Score on Score.studentId=Student.sId
------------------------------------------------
3.查询出所有没有参加考试的同学的学生编号,姓名,考试成绩。
select
sId,
sName
from Student
where sId not in(select studentId from Score)
------------------------------------------------
4使用联接重做:查询出所有没有参加考试的同学的学生编号,姓名。
--(1)
select sId,sName
from (
select sId,sName,sAge,score.*
from Student left outer join Score
on Score.studentId=Student.sId) as TB1
where scoreId is null
--(2)
select sId,sName
from (
select sId,sName,sAge,score.*
from Score right outer join Student
on Score.studentId=Student.sId) as TB1
where scoreId is null
------------------------------------------------
5、查询所有英语及格的学生姓名、年龄及成绩
select
sName,
sAge,
english
from Student
inner join Score
on Score.studentId=Student.sId
where english>=60