作者:月光魔术师2702935955 | 来源:互联网 | 2023-10-10 16:36
mysql求一个表中数据的平均值最大值最小值的存储过程!注意是存储过程!表名叫score。create or replace procedure (ave out number,t
mysql求一个表中数据的平均值 最大值 最小值的 存储过程!注意是存储过程!表名叫score。
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 Mathmaxchinesemax then
themax:=Mathmax;
else
themax:=chinesemax;
end if;
if themax englishmax then
themax:=themax;
else
themax:=englishmax;
end if;
---the min
if Mathminchinesemin 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;
mysql中怎么计算每行数据前五天的平均值
这是前4天的平均值,这个update语句不太好写呀,感觉你这个表设计有点问题
select avg(albvalue) from tablename where date between date_sub(date, interval 4 day) and date;
mysql中求平均值最高,或者count()最高最小等等……是有分组的。求教,谢谢。
给你举个例子,你自己按照你所在当前表的情况来进行查询。
例如:
select 列1 avg(列2) as xz from 表 group by 列1 order by xz desc ;
解释:
avg()函数是求某列的平均值,group by是对某列分组,按照SQL标准,分组要和聚合函数一起配合使用才有意义[虽然在mysql中不会报错]。order by xz desc表示的是对xz进行降序,就可以把最高的平均值算出来。