ACCP S1 SQL第十一章上机练习

上机1
select GradeId,sum(ClassHour) as 总学时数 from Subject 
group by GradeId order by sum(ClassHour)

select StudentNo,AVG(StudentResult) as '平均分' from Result
group by StudentNo

select SubjectId, AVG(StudentResult) as '平均分' from Result
group by SubjectId order by AVG(StudentResult) desc

select StudentNo,sum(StudentResult) as '总分' from Result
group by StudentNo order by sum(StudentResult) desc


上机2

select GradeId,COUNT(*)as '课程数' from Subject
group by GradeId having sum(ClassHour)>50

select GradeId,AVG(DATEDIFF(dd,BornDate,GETDATE())/365)as '平均年龄' from Student
group by GradeId

select GradeId,COUNT(*)as '学生人数' from Student
where Address like '北京%' group by GradeId

select StudentNo,AVG(StudentResult)as '平均分' from Result
group by StudentNo having AVG(StudentResult)>=60 order by AVG(StudentResult) desc

select SubjectId,AVG(StudentResult)as '平均分' from Result
where ExamDate='2013-03-22' and StudentResult>=60 group by SubjectId 

select StudentNo,count(StudentResult)as '不及格次数' from Result
where StudentResult<60 group by StudentNo

上机3

select StudentName,s.GradeId,phone from Student s
inner join Grade g on s.GradeId=g.GradeId

select GradeName,SubjectName,ClassHour from Subject j
inner join Grade g on j.GradeId=g.GradeId where g.GradeId=1 

select StudentName,StudentResult,ExamDate from Student s
inner join Result r on s.StudentNo=r.StudentNo where SubjectId=1

select SubjectName,StudentResult,ExamDate from Result r
inner join Subject s on s.SubjectId=r.SubjectId where StudentNo='S1101007'

select StudentNo,SubjectName,StudentResult,ExamDate from Result r
inner join Subject s on s.SubjectId=r.SubjectId where StudentResult<>0

上机4

select s.StudentNo,StudentName,SubjectName,StudentResult from Student s
inner join Subject j on j.GradeId=s.GradeId
inner join Result r on r.StudentNo=s.StudentNo

select StudentName,StudentResult,ExamDate from Student s
inner join Subject j on j.GradeId=s.GradeId
inner join Result r on r.StudentNo=s.StudentNo 
where SubjectName='面向对象程序设计'

上机5

select SubjectName,StudentNo,StudentResult from Subject s
left outer join Result r on r.SubjectId=s.SubjectId

select SubjectName,StudentNo,StudentResult from Subject s
left outer join Result r on r.SubjectId=s.SubjectId
where StudentResult is null

select GradeName,StudentNo,StudentName from Grade g
left outer join Student s on s.GradeId=g.GradeId

你可能感兴趣的:(ACCP S1 SQL第十一章上机练习)