stringsql=$@"SELECT sog.Student_Id,sog.GuestId,sog.OrderId,cou.CourseName,s.StuName as GuestName,og.CourseChapterNo,sa.AppointNum,ss.MakeUpNum FROM rb_student_orderguest sog
stringsql=$@"
SELECT sog.Student_Id,sog.GuestId,sog.OrderId,cou.CourseName,s.StuName as GuestName,og.CourseChapterNo,sa.AppointNum,ss.MakeUpNum
,o.CourseId
FROM rb_student_orderguest sog
INNER JOIN rb_order_guest og on sog.GuestId = og.Id
INNER JOIN rb_order o on sog.OrderId = o.OrderId
INNER JOIN rb_course cou on o.CourseId = cou.CourseId
INNER JOIN rb_student s on sog.Student_Id = s.StuId
INNER JOIN rb_class c on o.ClassId = c.ClassId
inner join rb_course_chapter cc on o.CourseId = cc.CourseId and cc.ParentId =0 and cc.ChapterGradeNo ={NextChapterGradeNo} and cc.CourseRate ={CourseGradeId}
LEFT JOIN (
SELECT sa1.StuId,COUNT(0) as AppointNum FROM rb_scroll_appointment sa1
INNER JOIN rb_student s1 on sa1.StuId = s1.StuId
WHERE sa1.`Status` =0 and sa1.State <>5 and sa1.Group_Id ={group_Id} and s1.StuName LIKE '%{stuName}%' and sa1.CourseGradeId ={CourseGradeId} and sa1.CourseGradeNo ={NextChapterGradeNo} GROUP BY sa1.StuId
SELECT sa1.StuId,COUNT(0) as AppointNum
FROM rb_scroll_appointment sa1 INNER JOIN rb_student s1 on sa1.StuId = s1.StuId
WHERE sa1.`Status` =0 and sa1.State <>5 and sa1.Group_Id ={group_Id} and s1.StuName LIKE '%{stuName}%' and sa1.CourseGradeId ={CourseGradeId} and sa1.CourseGradeNo ={NextChapterGradeNo} GROUP BY sa1.StuId
) sa on sog.Student_Id = sa.StuId
LEFT JOIN (
SELECT ss1.StuId,COUNT(0) as MakeUpNum FROM rb_scroll_skipcourse ss1
INNER JOIN rb_student s1 on ss1.StuId = s1.StuId
WHERE ss1.`Status` =0 and ss1.State =1 and ss1.Group_Id ={group_Id} and s1.StuName LIKE '%{stuName}%' and ss1.CourseGradeId ={CourseGradeId} and ss1.CourseGradeNo ={NextChapterGradeNo} GROUP BY ss1.StuId
SELECT ss1.StuId,COUNT(0) as MakeUpNum
FROM rb_scroll_skipcourse ss1 INNER JOIN rb_student s1 on ss1.StuId = s1.StuId
WHERE ss1.`Status` =0 and ss1.State =1 and ss1.Group_Id ={group_Id} and s1.StuName LIKE '%{stuName}%' and ss1.CourseGradeId ={CourseGradeId} and ss1.CourseGradeNo ={NextChapterGradeNo} GROUP BY ss1.StuId
) ss on sog.Student_Id = ss.StuId
WHERE o.Group_Id ={group_Id} and sog.`Status` =0 and og.GuestState NOT IN(2,7) and o.OrderState <>3 and c.ClassScrollType =2 and s.StuName LIKE '%{stuName}%'";
if(SchoolId>=0)
{
sql+=$@" and o.ScrollSchoolId ={SchoolId}";
}
sql+=string.Format(@" AND EXISTS (SELECT 1 FROM rb_course_chapter WHERE Status=0 AND CourseId= o.CourseId AND ParentId =0 AND ChapterGradeNo ={0} AND CourseRate ={1})",NextChapterGradeNo,CourseGradeId);