Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select
- g1.Courseid,
- g1.GradeValue MinGradeValue,
- isnull(min(g2.GradeValue)-1,100) MaxGradeValue,
- g1.Description
- from YourTable g1
- left join YourTable g2
- ON g2.CourseId = g1.CourseId
- and g2.GradeValue > g1.GradeValue
- group by
- g1.Courseid,
- g1.GradeValue,
- g1.Description
- SELECT courseId, description,
- gradeValue as minimumValue,
- LEAD(gradeValue) OVER(PARTITION BY courseId ORDER BY gradeValue) as nextGradeMinimumValue
- FROM Grade
- SELECT StudentGrade.studentId, StudentGrade.courseId, StudentGrade.grade,
- Grade.description
- FROM (VALUES(1, 1, 38),
- (2, 1, 99),
- (3, 2, 74.5),
- (4, 2, 120)) StudentGrade(studentId, courseId, grade)
- JOIN (SELECT courseId, description,
- gradeValue as minimumValue,
- LEAD(gradeValue) OVER(PARTITION BY courseId ORDER BY gradeValue) as nextGradeMinimumValue
- FROM Grade) Grade
- ON Grade.courseId = StudentGrade.courseId
- AND Grade.minimumValue >= StudentGrade.grade
- AND (Grade.nextGradeMinimumValue IS NULL OR Grade.nextGradeMinimumValue > StudentGrade.grade)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement