我编写查询以查找他参加的每门课程的学生成绩我还需要按他们的 ID 顺序对显示学生进行排序,我需要一个额外的属性来根据他的标记显示他的顺序
ALTER PROC [dbo].[REPStudentMarks]
(
@pClassID int,
@pSectionID int = null
)
AS
--Users.ClassID, Users.SectionID,
SELECT Users.FirstName, courses.Name, sum(UserExams.StudentMark) Mark,
ClassCourses.Minmark, ClassCourses.Maxmark
FROM courses
INNER JOIN Exams ON courses.CourseID = Exams.CourseID
INNER JOINUserExams ON Exams.ExamID = UserExams.ExamID
INNER JOIN Users ON UserExams.UserID = Users.UserID
INNER JOIN ClassCourses ON courses.CourseID = ClassCourses.CourseID
AND Exams.ClassID = ClassCourses.ClassID
AND Exams.CourseID = ClassCourses.CourseID
-- where Users.userID=1
group by Users.FirstName,courses.Name,ClassCourses.Minmark,ClassCourses.Maxmark,Users.ClassID,Users.SectionID
order by mark,Name desc
我在执行这个查询之后得到的行是这样的
FirstName, cName, sum(UserExams.StudentMark) Mark, Minmark, Maxmark,'Class Rankings', 'SectionRankings'
山姆,数学,90.0,50.0,100.0,1,1