stringsql="select * from (select a.ClassPlanId,c.TeacherName,b.ClassTimeId,c.TeacherHead,a.TeacherId,d.RoomName,b.StartTime,b.EndTime,a.PlanType,(case a.PlanType when 1 then (select CourseName from rb_course where CourseId=e.CouseId) when 2 then (select func_course_rate(CourseGradeId) from rb_scroll_appointment where ClassPlanId=a.ClassPlanId group by ClassPlanId) END) as CourseName,(case a.PlanType when 1 then (select (Count(0)+1) from rb_class_plan where `status`=0 and ClassId=a.ClassId and TO_Days(ClassDate)<TO_Days(a.ClassDate)) when 2 then (select CourseGradeNo from rb_scroll_appointment where ClassPlanId=a.ClassPlanId group by ClassPlanId) end) as Progress,(case a.PlanType when 1 then (select CourseRate from rb_course where CourseId=e.CouseId) when 2 then (select CourseGradeId from rb_scroll_appointment where ClassPlanId=a.ClassPlanId group by ClassPlanId) END) as CourseRate from rb_class_plan a left join rb_class_time b on a.ClassPlanId=b.ClassPlanId left join rb_teacher c on a.TeacherId=c.TId left join rb_class_room d on a.ClassRoomId = d.RoomId left join rb_class e on a.ClassId=e.ClassId where TO_Days(a.ClassDate)=TO_Days(now()) and c.TId=@tid and a.`status`=0 and b.EndTime>=DATE_FORMAT(now(),'%H:%i') and a.Group_Id=@gid and a.ClassRoomId=@roomId union all select ReserveClassId as ClassPlanId,b.TeacherName,ReserveClassId as ClassTimeId,b.TeacherHead,a.TeacherId,c.RoomName,a.ClassTime as StartTime,a.EndTime,3 as PlanType,a.ClassContent as CourseName,1 as Progress,1 as CourseRate from rb_reserve_class a left join rb_teacher b on a.TeacherId=b.TId left join rb_class_room c on a.ClassRoomId=c.RoomId where TO_Days(a.ClassDate)=TO_Days(now()) and b.TId=@tid and a.EndTime>=DATE_FORMAT(now(),'%H:%i') and a.`Status`=0 and a.Group_Id=@gid and a.ClassRoomId=@roomId) as aa order by aa.StartTime";
stringsql="select * from (select a.ClassId,b.ClassStatus,a.ClassPlanId,c.TeacherName,b.ClassTimeId,c.TeacherHead,a.TeacherId,d.RoomName,b.StartTime,b.EndTime,a.PlanType,(case a.PlanType when 1 then (select CourseName from rb_course where CourseId=e.CouseId) when 2 then (select func_course_rate(CourseGradeId) from rb_scroll_appointment where ClassPlanId=a.ClassPlanId group by ClassPlanId) END) as CourseName,(case a.PlanType when 1 then (select (Count(0)+1) from rb_class_plan where `status`=0 and ClassId=a.ClassId and TO_Days(ClassDate)<TO_Days(a.ClassDate)) when 2 then (select CourseGradeNo from rb_scroll_appointment where ClassPlanId=a.ClassPlanId group by ClassPlanId) end) as Progress,(case a.PlanType when 1 then (select CourseRate from rb_course where CourseId=e.CouseId) when 2 then (select CourseGradeId from rb_scroll_appointment where ClassPlanId=a.ClassPlanId group by ClassPlanId) END) as CourseRate from rb_class_plan a left join rb_class_time b on a.ClassPlanId=b.ClassPlanId left join rb_teacher c on a.TeacherId=c.TId left join rb_class_room d on a.ClassRoomId = d.RoomId left join rb_class e on a.ClassId=e.ClassId where TO_Days(a.ClassDate)=TO_Days(now()) and c.TId=@tid and a.`status`=0 and b.EndTime>=DATE_FORMAT(now(),'%H:%i') and a.Group_Id=@gid and a.ClassRoomId=@roomId union all select 0 as ClassId,0 as ClassStatus,ReserveClassId as ClassPlanId,b.TeacherName,ReserveClassId as ClassTimeId,b.TeacherHead,a.TeacherId,c.RoomName,a.ClassTime as StartTime,a.EndTime,3 as PlanType,a.ClassContent as CourseName,1 as Progress,1 as CourseRate from rb_reserve_class a left join rb_teacher b on a.TeacherId=b.TId left join rb_class_room c on a.ClassRoomId=c.RoomId where TO_Days(a.ClassDate)=TO_Days(now()) and b.TId=@tid and a.EndTime>=DATE_FORMAT(now(),'%H:%i') and a.`Status`=0 and a.Group_Id=@gid and a.ClassRoomId=@roomId) as aa order by aa.StartTime";
varsql="select IFNULL(MAX(GuestId),0) as GuestId from rb_student_orderguest a where Student_Id=@stuId and a.GuestId in(select IF(b.PlanType=2,c.GuestId,e.Id) as GuestId from rb_class_time a left join rb_class_plan b on a.ClassPlanId=b.ClassPlanId left join rb_scroll_appointment c on b.ClassPlanId=c.ClassPlanId and b.PlanType=2 left join rb_class d on a.ClassId=d.ClassId and b.PlanType!=2 left join rb_order_guest e on e.ClassId=d.ClassId where ClassTimeId=@timeId)";