,sc.StopClassEffectTime,B.SourceOrderId,B.TargetOrderId,IFNULL(D.FirstClassHours,0)+IFNULL(D.SecondClassHours,0)+IFNULL(D.ThirdClassHours,0) AS ContractTotalHours
FROM RB_Order_Guest AS A LEFT JOIN rb_order AS B ON A.OrderId=B.OrderId
FROM RB_Order_Guest AS A LEFT JOIN rb_order AS B ON A.OrderId=B.OrderId
LEFT JOIN rb_course AS C ON (B.CourseId=C.CourseId AND B.CourseId>0 AND B.OrderType=1)
LEFT JOIN rb_course AS C ON (B.CourseId=C.CourseId AND B.CourseId>0 AND B.OrderType=1)
LEFT JOIN (SELECT OrderGuestId,MAX(TakeEffectTime) as StopClassEffectTime from rb_student_stopclass where IsAuditThrough=1 GROUP BY OrderGuestId) as sc on sc.OrderGuestId=a.Id
LEFT JOIN (SELECT OrderGuestId,MAX(TakeEffectTime) as StopClassEffectTime from rb_student_stopclass where IsAuditThrough=1 GROUP BY OrderGuestId) as sc on sc.OrderGuestId=a.Id
LEFT JOIN rb_education_contract AS D ON A.OrderId=D.OrderId AND A.Id=D.GuestId AND D.IsSystemUse=1