USE StudentScore
GO
CREATE PROCEDURE ST_XYFX @StudentID int
/*存储过程ST_XYFX指定的参数@StudentID是输入参数*/
AS
SELECT CourseName
from
Student,score,Course
where student.StudentID=Score.StudentID and Course .CourseID=Score.CourseID and Student.StudentID=@StudentID
GROUP BY CourseName
SELECT AVG(Grade) AS '平均分'
FROM Course a,Score b,Student c
where b.StudentID = @StudentID and a.CourseID =b.CourseID and b.StudentID =c.StudentID
select d.CourseName as '最高分课程'
from
(SELECT MAX(Grade) AS '最高成绩',Student.StudentID ,CourseName
FROM Student join score
on student.StudentID=Score.StudentID
join Course
on Course.CourseID=Score.CourseID
where Grade =(Select max(Grade) From Score
where Student.StudentID= @StudentID)
Group BY Student .StudentID ,CourseName,Grade )d
where d.StudentID= @StudentID
select e.CourseName as '最低分课程'
from
(SELECT MIN(Grade) AS '最低成绩',Student.StudentID ,CourseName
FROM Student join score
on student.StudentID=Score.StudentID
join Course
on Course.CourseID=Score.CourseID
where Grade =(Select min(Grade) From Score
where Student.StudentID= @StudentID)
Group BY Student .StudentID ,CourseName,Grade )e
where e.StudentID= @StudentID