SELECT A.StuId,A.CreateBy,A.StuChannel,A.CreateType,IFNULL(B.VisitCount,0) AS VisitCount,IFNULL(C.CourseOrderCount,0) AS OrderCount,IFNULL(c.Income,0) AS OrderInCome
,A.CustomerId,A.StuSourceId,IFNULL(D.CustomerSourceType,0) AS CustomerSourceType
,A.CustomerId,A.StuSourceId,IFNULL(D.CustomerType,0) AS CustomerType
FROM RB_Student AS A
LEFT JOIN(SELECT StuId,Count(1) AS VisitCount FROM rb_student_visit WHERE Status=0 GROUP BY StuId) AS B ON A.StuId=B.StuId
LEFT JOIN(SELECT og.Student_Id,COUNT(1) AS CourseOrderCount,SUM(o.Income) AS Income FROM rb_student_orderguest AS og INNER JOIN rb_order AS o ON og.OrderId=o.OrderId WHERE O.OrderState NOT IN(3,4) GROUP BY og.Student_Id ) AS C ON A.StuId=C.Student_Id