select
COUNT(case when info.State = '0' then State end ) as daichuliCount,
COUNT(case when info.State = '1' then State end ) as yichuliCount,
COUNT(case when info.State IN('0','1') then State end) as allCount
from cloud_crmandsupportorder as info
where 1=1
and DATEDIFF(info.CreateDate,NOW())=-1
and info.UserId=''
;
select sClass 班级,count(*) 班级学生总人数,
sum(case when sGender=0 then 1 else 0 end) 该班级女生人数,
sum(case when sGender=0 then 1 else 0 end)*1.0/count(*) 该班级女生所占比例,
sum(case when sGender=1 then 1 else 0 end) 该班级男生人数,
sum(case when sGender=1 then 1 else 0 end)*1.0 /count(*) 该班级男生所占比例
from student GROUP BY sClass ORDER BY sClass asc