mysql求平均值最大值最小值_mysql求一个表中数据的平均值 最大值 最小值的 存储过程!注意是存储过程!表名叫score。...

创建了一个MySQL存储过程,用于计算score表中Math、Chinese和English三个字段的平均值、最大值和最小值。通过比较找出各科的最大和最小值,并计算三科总成绩的平均值。
摘要由CSDN通过智能技术生成

展开全部

create or replace procedure (ave out number,themax out number,themin varchar2)is

Mathmax number;

Mathmin number;

chinesemax number;

chinesemin number;

englishmax number;

englishmin number;

totle number;

sum1 number;

sum2 number;

sum3 number;

count1 number;

begin

select Math into Mathmax from score where 1=1 order by desc;

select Math into Mathmin from score where 1=1 order by asc;

select chinese into chinesemin from score where 1=1 order by asc;

select chinese into chinesemax from score where 1=1 order by desc;

select english into englishmax from score where 1=1 order by desc;

select english into englishmin from score where 1=1 order by asc;

---the max

if Mathmax>chinesemax then

themax:=Mathmax;

else

themax:=chinesemax;

end if;

if themax > englishmax then

themax:=themax;

else

themax:=englishmax;

end if;

---the min

if Mathmin>chinesemin then

themin:=chinesemin;

else

themin:=Mathmin;

end if;

if themin > englishmin then

themin:=englishmin;

else

themin:=themin;

end if;

--the average

select count(1) into count1 from score;

select sum(math) into sum1 from score;

select sum(chinese) into sum2 from score;

select sum(english) into sum3 from score;

ave:=(sum1+sum2+sum3)/count1;

end;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值