SELECT A.*,IFNULL(B.StuName,'') AS VisitorName,C.ClassDate,C.ClassTime,C.EndTime,C.ClassContent,IFNULL(D.TeacherName,'') AS TeacherName,IFNULL(E.RoomName,'') AS RoomName
,IFNULL(B.StuTel,'') AS StuTel,IFNULL(F.LessonName,'') AS LessonName,IFNULL(B.QQ,'') AS QQ,IFNULL(B.WeChatNo,'') AS WeChatNo,C.ReserveType,C.ClassPlanId
,IFNULL(G.OrderCount,0) AS OrderCount
FROM RB_Visitor_Reserve AS A LEFT JOIN rb_student AS B ON A.Visitor_Id=B.StuId
LEFT JOIN
(
SELECT Student_Id,COUNT(1) AS OrderCount
FROM rb_student_orderguest AS sog INNER JOIN rb_order AS orderTab ON sog.OrderId=orderTab.OrderId AND orderTab.OrderState IN(1)
GROUP BY Student_Id
) AS G ON A.Visitor_Id=G.Student_Id
LEFT JOIN rb_reserve_class AS C ON A.ReserveClassId=C.ReserveClassId
LEFT JOIN rb_teacher AS D ON C.TeacherId=D.TId
LEFT JOIN rb_class_room AS E ON C.ClassRoomId=E.RoomId