--查询每学期学时数超过50的课程数 SELECT GradeId,COUNT(SubjectName) as 课时数,sum(ClassHour)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 SUM(StudentResult) desc --查询考试日期为2013年3月22日的课程的及格平均分 SELECT SubjectId,AVG(StudentResult*0.6)as 及格平均分 FROM Result WHERE ExamDate='2013-3-22' GROUP BY SubjectId --查询至少一次考试不及格的学生学号,不及格次数 SELECT StudentNo,COUNT(*)AS 次数 FROM Result WHERE StudentResult>60 GROUP BY StudentNo