SELECT A.*,IFNULL(B.GuestName,'') AS GuestName,ec.ContractNo,ec.Id as ContractId,IFNULL(C.SName,'') AS SchoolName,IFNULL(D.ClassName,'') AS ClassName,IFNULL(T.TeacherName,'') AS TeacherName
,IFNULL(E.EnterID,0) AS EnterID,IFNULL(F.CourseName,'') AS CourseName,D.ClassNo
,IFNULL(E.EnterID,0) AS EnterID,IFNULL(F.CourseName,'') AS CourseName,D.ClassNo,B.TotalHours,B.CompleteHours
FROM RB_Student_BackClass AS A LEFT JOIN rb_order_guest AS B ON A.GuestId=B.Id
LEFT JOIN rb_education_contract ec on B.Id = ec.GuestId and ec.Status <>4