Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. select
  2. g1.Courseid,
  3. g1.GradeValue MinGradeValue,
  4. isnull(min(g2.GradeValue)-1,100) MaxGradeValue,
  5. g1.Description
  6. from YourTable g1
  7. left join YourTable g2
  8. ON g2.CourseId = g1.CourseId
  9. and g2.GradeValue > g1.GradeValue
  10. group by
  11. g1.Courseid,
  12. g1.GradeValue,
  13. g1.Description
  14.  
  15. SELECT courseId, description,
  16. gradeValue as minimumValue,
  17. LEAD(gradeValue) OVER(PARTITION BY courseId ORDER BY gradeValue) as nextGradeMinimumValue
  18. FROM Grade
  19.  
  20. SELECT StudentGrade.studentId, StudentGrade.courseId, StudentGrade.grade,
  21. Grade.description
  22. FROM (VALUES(1, 1, 38),
  23. (2, 1, 99),
  24. (3, 2, 74.5),
  25. (4, 2, 120)) StudentGrade(studentId, courseId, grade)
  26. JOIN (SELECT courseId, description,
  27. gradeValue as minimumValue,
  28. LEAD(gradeValue) OVER(PARTITION BY courseId ORDER BY gradeValue) as nextGradeMinimumValue
  29. FROM Grade) Grade
  30. ON Grade.courseId = StudentGrade.courseId
  31. AND Grade.minimumValue >= StudentGrade.grade
  32. AND (Grade.nextGradeMinimumValue IS NULL OR Grade.nextGradeMinimumValue > StudentGrade.grade)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement