Hi Amritha44,
This is simple function in my SQL
mysql> DELIMITER |
mysql>
CREATE FUNCTION WEIGHTED_AVERAGE (n1 INT, n2 INT, n3 INT, n4 INT)
RETURNS INT
DETERMINISTIC
BEGIN
DECLARE avg INT;
SET avg = (n1+n2+n3*2+n4*4)/8;
RETURN avg;
END|
Query OK, 0 rows affected (0.00 sec)
mysql>
You can run your function :
SELECT WEIGHTED_AVERAGE(70,65,65,60)\G
Output is :
WEIGHTED_AVERAGE(70,65,65,60): 63
1 row in set (0.00 sec)
Refer this link for detailed explaination of this example :
http://www.databasejournal.com/features/mysql/article.php/3569846/MySQL-Stored-Functions.htm
Thanks,
Radha Srikanth
Amritha444, if this helps please login to Mark As Answer. | Alert Moderator