declare @c numeric(5,2)
declare @c1 int, @c2 int, @c3 int, @c4 int
set @c1=0; set @c2=0; set @c3=0; set @c4=0
declare xxx cursor
for select 成绩 from score
open xxx
fetch xxx into @c
while @@fetch_status=0
begin
if(@c>=90) set @c1=@c1+1;
else if(@c>=70) set @c2=@c2+1;
else if(@c>=60) set @c3=@c3+1;
else set @c4=@c4+1
fetch from xxx into @c
end
close xxx
deallocate xxx
print '优秀生人数:'+str(@c1,5);
print '良好生人数:'+str(@c2,5);
print '及格生人数:'+str(@c3,5);
print '及格生人数:'+str(@c4,5)
从score表中按成绩统计并显示出优秀、良好、及格、不及格各多少人。