SELECT a.*,IFNULL(c.ScoreNum,0) AS ScoreNum,IFNULL(c.ScoreCount,0) AS ScoreCount
FROM {TableName} AS a
LEFT JOIN (SELECT StudentSurveyId,SUM(ScoreNum) as ScoreNum,COUNT(GuestSurveyId) as ScoreCount FROM Rb_Education_StudentSurveyDetails WHERE ScoreNum>0 GROUP BY StudentSurveyId ) as c ON a.ID=c.StudentSurveyId
WHERE a.state=0");
if(where!=null)
{
if(where.StudentId>0)
{
sb.AppendFormat(" and a.StudentId={0}",where.StudentId);
}
if(where.TeacherId>0)
{
sb.AppendFormat(" and a.TeacherId={0}",where.TeacherId);
SELECT a.*,IFNULL(c.ScoreNum,0) AS ScoreNum,IFNULL(c.ScoreCount,0) AS ScoreCount
FROM {TableName} AS a
LEFT JOIN (SELECT StudentSurveyId,SUM(ScoreNum) as ScoreNum,COUNT(StudentSurveyId) as ScoreCount FROM Rb_Education_StudentSurveyDetails WHERE ScoreNum>0 GROUP BY StudentSurveyId ) as c ON a.ID=c.StudentSurveyId
WHERE a.state=0");
if(where!=null)
{
if(where.StudentId>0)
{
sb.AppendFormat(" and a.StudentId={0}",where.StudentId);
}
if(where.TeacherId>0)
{
sb.AppendFormat(" and a.TeacherId={0}",where.TeacherId);
}
if(!string.IsNullOrEmpty(where.QStartDate))
{
sb.AppendFormat(" AND A.CreateDate>='{0}' ",where.QStartDate);
}
if(!string.IsNullOrEmpty(where.QEndDate))
{
sb.AppendFormat(" AND A.CreateDate<='{0} 23:59:59' ",where.QEndDate);
builder.AppendFormat(" AND t.{0}={1} ",nameof(RB_Student_ViewModel.ProviceId),query.ProviceId);
}
if(query.CityId>0)
{
builder.AppendFormat(" AND t.{0}={1} ",nameof(RB_Student_ViewModel.CityId),query.CityId);
}
if(query.AreaId>0)
{
builder.AppendFormat(" AND t.{0}={1} ",nameof(RB_Student_ViewModel.AreaId),query.AreaId);
}
if(query.CustomerId>0)
{
builder.AppendFormat(" AND t.{0}={1} ",nameof(RB_Student_ViewModel.CustomerId),query.CustomerId);
}
if(query.StuId>0)
{
builder.AppendFormat(" AND t.{0}={1} ",nameof(RB_Student_ViewModel.StuId),query.StuId);
}
if(!string.IsNullOrEmpty(query.StuIds))
{
builder.AppendFormat(" AND t.{0} in({1}) ",nameof(RB_Student_ViewModel.StuId),query.StuIds);
}
if(query.StuStage>0)
{
builder.AppendFormat(" AND t.{0}={1} ",nameof(RB_Student_ViewModel.StuStage),(int)query.StuStage);
}
if(query.CreateBy>0)
{
builder.AppendFormat(" AND t.{0}={1} ",nameof(RB_Student_ViewModel.CreateBy),query.CreateBy);
}
if(!string.IsNullOrEmpty(query.QCreateBys))
{
builder.AppendFormat(@" AND (t.CreateBy IN({0}) OR t.StuId IN(SELECT StuId FROM rb_student_assist WHERE AssistId IN({0}) AND `Status`= 0) ) ",query.QCreateBys);
}
if(!string.IsNullOrEmpty(query.StartTime))
{
builder.AppendFormat(" AND t.{0}>='{1}' ",nameof(RB_Student_ViewModel.CreateTime),query.StartTime);
}
if(!string.IsNullOrEmpty(query.EndTime))
{
builder.AppendFormat(" AND t.{0}<='{1} 23:59:59' ",nameof(RB_Student_ViewModel.CreateTime),query.EndTime);