SELECT t.*,g.GroupName,s.SName,IFNULL(a.Account,'') AS StudentAccount ,c.CustomerName,IFNULL(B.Name,'') AS AdvisorStatusName
SELECT t.*,g.GroupName,s.SName,IFNULL(a.Account,'') AS StudentAccount,c.CustomerName,IFNULL(B.Name,'') AS AdvisorStatusName,sf.MaxFollowTime
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.StuSourceId AND t.CreateType=2)
...
...
@@ -281,6 +281,9 @@ FROM rb_student AS t LEFT JOIN rb_group AS g ON t.Group_Id=g.GId
WHERE B.OrderState IN(1)
GROUP BY A.Student_Id
) AS org ON t.StuId=org.Student_Id
LEFT JOIN (
SELECT StuId,MAX(UpdateTime) AS MaxFollowTime FROM rb_student_follow WHERE Status=0 GROUP BY StuId
) AS sf ON t.StuId=sf.StuId
WHERE 1=1
");
if(query!=null)
...
...
@@ -501,7 +504,19 @@ WHERE 1=1
builder.AppendFormat(" AND Exists (SELECT StuId FROM rb_student_follow WHERE `Status`=0 AND t.StuId=StuId AND CreateBy={0} AND CreateTime>='{1}' AND CreateTime<='{2} 23:59:59') ",query.CreateBy,query.FollowStartTime,query.FollowEndTime);
}
}
builder.AppendFormat(" ORDER BY t.{0} DESC ",nameof(RB_Student_ViewModel.StuId));
if(query.QOrderBy==1)
{
builder.AppendFormat(" ORDER BY sf.MaxFollowTime DESC ");
}
elseif(query.QOrderBy==2)
{
builder.AppendFormat(" ORDER BY sf.MaxFollowTime ASC ");
}
else
{
builder.AppendFormat(" ORDER BY t.{0} DESC ",nameof(RB_Student_ViewModel.StuId));