Home Stored Functions UDF Function to calculate average for static number of values

Function to calculate average for static number of values

Function Name:
get_average
Function type:
UDF
Input variables:
Integers
Output:
Returns single Integer

The purpose of this function is to calculate the average of a set number of integer values.


Function

DELIMITER $$
DROP FUNCTION IF EXISTS `sportszone`.`get_average` $$
CREATE DEFINER=`root`@`localhost` FUNCTION `get_average`(stat1 INT, stat2 INT, stat3 INT, stat4 INT) RETURNS int(11)
DETERMINISTIC
BEGIN
DECLARE stat_avg INT;
SET stat_avg = (stat1+stat2+stat3+stat4)/4;
RETURN stat_avg;
END $$
DELIMITER ;

Select Function

Select get_average(195,238,390,295) as 'Batting Average over 4 Seasons';

Result Set

Batting Average over 4 Seasons

280

Who's Online
We have 23 guests online