院校招生情况统计 COLLEGE_TOTAL

create or replace procedure COLLEGE_TOTAL is
--定义一个记录
type t_AuthRec is record(
coid number,
avgscorce number,
maxscorce number,
minscorce number,
totalnum number,
boynum number,
girlnum number
);
--定义记录表下标索引
i binary_integer := -1 ;
--定义记录表类型
type tmp_table_type is table of t_AuthRec index by binary_integer ;
--定义记录表变量
v_tmp_table tmp_table_type ;
[color=darkred][size=x-large] --decode分支函数,常用于count()的统计判断[/size][/color]cursor v_college_list is select c.collegeid,avg(ts.totalsco),max(ts.totalsco),min(ts.totalsco),c.actual_total,count(decode(sex,0,sex,1,null)) boy,c.actual_total -count(decode(sex,0,sex,1,null)) girl
from college c,mat m,student s,totalscore ts where c.collegeid=m.mat_collegeid and s.stuid=m.stuid and ts.stuid=s.stuid
group by c.collegeid ,c.actual_total

[color=red][size=x-large]
[size=small]--使用avg,max,min,count等统计函数时,必须要有gounp by,否则无法正常输出!![/size][/size][/color]----------------------------------------------------------------------
order by avg(ts.totalsco) desc;

begin
--给记录表变量赋值
for v_record in v_college_list loop
v_tmp_table(i) :=v_record ;
i := i + 1 ;
end loop;

--输出记录表变量的值
for j in v_tmp_table.first..v_tmp_table.last loop
--记录表,输出自定义类型的变量名v_tmp_table(j).coid!!!
Dbms_Output.put_line('院校编号:'||v_tmp_table(j).coid);
Dbms_Output.put_line('平均分数:'||v_tmp_table(j).avgscorce);
Dbms_Output.put_line('最大分数:'||v_tmp_table(j).maxscorce);
Dbms_Output.put_line('最小分数:'||v_tmp_table(j).minscorce);
Dbms_Output.put_line('录取总人数:'||v_tmp_table(j).totalnum);
Dbms_Output.put_line('男人数:'||v_tmp_table(j).boynum);
Dbms_Output.put_line('女人数:'||v_tmp_table(j).girlnum);
end loop;


end COLLEGE_TOTAL;

--过程名和参数:COLLEGE_TOTAL
--功能:按照院校的平均录取分数排序所有院校,统计各院校的最高分数、
--最低分数,招生人数、录取人数、男生人数、女生人数等信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值