成绩分段统计
CREATE PROCEDURE select_MarkContrastByClass
@semester_id int,
@grade_id int,
@achievementName varchar(50),
@tSubject_id int,
@rate decimal,
@choiceClass int,
@selfClass int
AS
BEGIN
select 班级,
count(s_id) as 考试人数,
sum(scoreNumber) as 总分,
cast(avg(scoreNumber) as decimal(10,2)) as 平均分,
sum(case when scoreNumber=100 then 1 else 0 end ) as '100',
sum(case when scoreNumber<100 and scoreNumber>=95 then 1 else 0 end ) as '99-95',
sum(case when scoreNumber<95 and scoreNumber>=90 then 1 else 0 end ) as '94-90',
sum(case when scoreNumber<90 and scoreNumber>=85 then 1 else 0 end ) as '89-85',
sum(case when scoreNumber<85 and scoreNumber>=80 then 1 else 0 end ) as '84-80',
sum(case when scoreNumber<80 and scoreNumber>=75 then 1 else 0 end ) as '79-75',
sum(case when scoreNumber<75 and scoreNumber>=70 then 1 else 0 end ) as '74-70',
sum(case when scoreNumber<70 and scoreNumber>=65 then 1 else 0 end ) as '69-65',
sum(case when scoreNumber<65 and scoreNumber>=60 then 1 else 0 end ) as '64-60',
sum(case when scoreNumber>=60 then 1 else 0 end ) as '合格人数',
case
when sum(case when scoreNumber>=60 then 1 else 0 end )=0 then 0
when count(s_id)=0 then 0
else cast(100*sum(cast(case when scoreNumber>=60 then 1 else 0 end as decimal))/count(s_id) as decimal(10,2))
end
as '合格率',
sum(case when scoreNumber>=@rate then 1 else 0 end ) as '达标人数',
case
when sum(case when scoreNumber>=@rate then 1 else 0 end )=0 then 0
when count(s_id)=0 then 0
else cast(100*sum(cast(case when scoreNumber>=@rate then 1 else 0 end as decimal))/count(s_id) as decimal(10,2))
end
as '达标率',
sum(case when scoreNumber<60 and scoreNumber>=50 then 1 else 0 end ) as '59-50',
sum(case when scoreNumber<50 and scoreNumber>=40 then 1 else 0 end ) as '49-40',
sum(case when scoreNumber<40 and scoreNumber>=30 then 1 else 0 end ) as '39-30',
sum(case when scoreNumber<30 and scoreNumber>=20 then 1 else 0 end ) as '29-20',
sum(case when scoreNumber<20 and scoreNumber>=10 then 1 else 0 end ) as '19-10',
sum(case when scoreNumber<10 and scoreNumber>=0 then 1 else 0 end ) as '9-0',
sum(case when scoreNumber<60 then 1 else 0 end ) as '不及格人数',
case
when sum(case when scoreNumber<60 then 1 else 0 end )=0 then 0
when count(s_id)=0 then 0
else cast(100*sum(cast(case when scoreNumber<60 then 1 else 0 end as decimal))/count(s_id) as decimal(10,2))
end
as '不及格率',
教者
from dbo.aAchievementMarkWithTeacherView where (@choiceClass=0 and achievementName=@achievementName and tSubject_id=@tSubject_id and semester_id=@semester_id and grade_id=@grade_id) or (@choiceClass!=0 and achievementName=@achievementName and tSubject_id=@tSubject_id and semester_id=@semester_id and yc_id in (@selfClass,@choiceClass)) group by yc_id,班级,教者 order by yc_id
END
GO
CREATE PROCEDURE select_MarkContrastByClass
@semester_id int,
@grade_id int,
@achievementName varchar(50),
@tSubject_id int,
@rate decimal,
@choiceClass int,
@selfClass int
AS
BEGIN
select 班级,
count(s_id) as 考试人数,
sum(scoreNumber) as 总分,
cast(avg(scoreNumber) as decimal(10,2)) as 平均分,
sum(case when scoreNumber=100 then 1 else 0 end ) as '100',
sum(case when scoreNumber<100 and scoreNumber>=95 then 1 else 0 end ) as '99-95',
sum(case when scoreNumber<95 and scoreNumber>=90 then 1 else 0 end ) as '94-90',
sum(case when scoreNumber<90 and scoreNumber>=85 then 1 else 0 end ) as '89-85',
sum(case when scoreNumber<85 and scoreNumber>=80 then 1 else 0 end ) as '84-80',
sum(case when scoreNumber<80 and scoreNumber>=75 then 1 else 0 end ) as '79-75',
sum(case when scoreNumber<75 and scoreNumber>=70 then 1 else 0 end ) as '74-70',
sum(case when scoreNumber<70 and scoreNumber>=65 then 1 else 0 end ) as '69-65',
sum(case when scoreNumber<65 and scoreNumber>=60 then 1 else 0 end ) as '64-60',
sum(case when scoreNumber>=60 then 1 else 0 end ) as '合格人数',
case
when sum(case when scoreNumber>=60 then 1 else 0 end )=0 then 0
when count(s_id)=0 then 0
else cast(100*sum(cast(case when scoreNumber>=60 then 1 else 0 end as decimal))/count(s_id) as decimal(10,2))
end
as '合格率',
sum(case when scoreNumber>=@rate then 1 else 0 end ) as '达标人数',
case
when sum(case when scoreNumber>=@rate then 1 else 0 end )=0 then 0
when count(s_id)=0 then 0
else cast(100*sum(cast(case when scoreNumber>=@rate then 1 else 0 end as decimal))/count(s_id) as decimal(10,2))
end
as '达标率',
sum(case when scoreNumber<60 and scoreNumber>=50 then 1 else 0 end ) as '59-50',
sum(case when scoreNumber<50 and scoreNumber>=40 then 1 else 0 end ) as '49-40',
sum(case when scoreNumber<40 and scoreNumber>=30 then 1 else 0 end ) as '39-30',
sum(case when scoreNumber<30 and scoreNumber>=20 then 1 else 0 end ) as '29-20',
sum(case when scoreNumber<20 and scoreNumber>=10 then 1 else 0 end ) as '19-10',
sum(case when scoreNumber<10 and scoreNumber>=0 then 1 else 0 end ) as '9-0',
sum(case when scoreNumber<60 then 1 else 0 end ) as '不及格人数',
case
when sum(case when scoreNumber<60 then 1 else 0 end )=0 then 0
when count(s_id)=0 then 0
else cast(100*sum(cast(case when scoreNumber<60 then 1 else 0 end as decimal))/count(s_id) as decimal(10,2))
end
as '不及格率',
教者
from dbo.aAchievementMarkWithTeacherView where (@choiceClass=0 and achievementName=@achievementName and tSubject_id=@tSubject_id and semester_id=@semester_id and grade_id=@grade_id) or (@choiceClass!=0 and achievementName=@achievementName and tSubject_id=@tSubject_id and semester_id=@semester_id and yc_id in (@selfClass,@choiceClass)) group by yc_id,班级,教者 order by yc_id
END
GO