开发者

Find min/max of input values in stored procedures, MySQL

Is there any easy way to find m开发者_如何学运维in/max value in the set of input values in stored procedures?

For example:

delimiter $$
create procedure extremevalues ( in a1 int, in a2 int , 
                                 in a3 int, in a4 int, 
                                 in a5 int, min_a int, max_a int)
begin
set max_a:=.... ;
set min_a:=.... ;
select max_a, min_a;
end$$

I know one can use aggregate functions max() and min() in the select statement while working with tables.

I could not find any reference to the similar problem.

Thank you.


set @a:=1, @b:=2, @c:=3;
set @max:=greatest(@a, @b, @c);
set @min:=least(@a, @b, @c);
select @max, @min;

to fit into SP,


delimiter $$
create procedure extremevalues ( in a1 int, in a2 int ,
                                 in a3 int, in a4 int,
                                 in a5 int, min_a int, max_a int)
begin
set max_a:=greatest(a1, a2, a2, a3, a4, a5);
set min_a:=least(a1, a2, a2, a3, a4, a5);
select max_a, min_a;
end$$
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜