SET a.ChapterNo = a.ChapterNo +{ChapterNum},a.CourseGradeId = (SELECT CourseRate FROM rb_course_chapter c WHERE c.Group_Id ={groupId} and c.CourseId =a.LearnCourseId and c.ChapterNo =a.ChapterNo)
,a.CourseGradeNo = (SELECT ChapterGradeNo FROM rb_course_chapter c WHERE c.Group_Id ={groupId} and c.CourseId =a.LearnCourseId and c.ChapterNo =a.ChapterNo)
SELECT og.*,o.CourseId,g.CourseChapterNo,c.ClassScrollType,o.ScrollSchoolId,g.TotalHours,g.CompleteHours,IFNULL(cc.CheckHours,0) AS CheckHours
FROM rb_student_orderguest og
INNER JOIN rb_order_guest g on og.GuestId = g.Id
INNER JOIN rb_order o on og.OrderId = o.OrderId
INNER JOIN rb_class c on o.ClassId = c.ClassId
LEFT JOIN (SELECT OrderGuestId,SUM(CurrentDeductionHours) AS CheckHours FROM rb_class_check WHERE Status=0 GROUP BY OrderGuestId) AS cc ON og.GuestId=cc.OrderGuestId
WHERE og.Status =0 AND g.`Status` =0 AND o.OrderState <>3 AND o.OrderType =1