SELECT t.*,g.GroupName,s.SName,IFNULL(a.Account,'') AS StudentAccount ,c.CustomerName,IFNULL(B.Name,'') AS AdvisorStatusName
FROM rb_student AS t LEFT JOIN rb_group AS g ON t.Group_Id=g.GId
LEFT JOIN rb_school AS s ON t.School_Id=s.SId
LEFT JOIN rb_customer c on c.CustomerId = t.CustomerId
LEFT JOIN rb_customer c on (c.CustomerId = t.StuSourceId AND t.CreateType=2)
LEFT JOIN rb_account as a ON (t.StuId=a.AccountId AND a.AccountType=4 )
LEFT JOIN rb_student_advisorconfig AS b ON t.AdvisorStatus=B.Id
WHERE 1=1
...
...
@@ -1080,11 +1080,12 @@ WHERE 1=1
StringBuilderbuilder=newStringBuilder();
builder.AppendFormat(@"
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.CustomerType,0) AS CustomerType,IFNULL(D.CategoryId,0) AS CategoryId
,A.CustomerId,A.StuSourceId,IFNULL(D.CustomerType,0) AS CustomerType,IFNULL(D.CategoryId,0) AS CategoryId,IFNULL(E.CategoryName,'') AS CategoryName,IFNULL(E.CatetoryType,0) AS CatetoryType
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
LEFT JOIN rb_customer AS D ON A.StuSourceId=D.CustomerId AND A.CreateType=2
LEFT JOIN rb_customer_category AS E ON D.CategoryId=E.CategoryId