I'm trying to create a function in MySQL that returns the sum of each row's difference between two of its decimal values. This statement works correctly:
SELECT SUM(ending_mileage - beginning_mileage) AS total_mileage FROM trip;
When I attempt to put this into a function to be easily accessed in my project, I get syntax errors on the parenthesis after trip saying "Statement is incomplete, expecting ';'" and on the END saying "END is not valid at this position". Is there some kind of syntax that I am not stating correctly?
CREATE FUNCTION fnMileageTotal()
RETURNS DECIMAL
BEGIN
RETURN (SELECT SUM(ending_mileage - beginning_mileage) FROM trip);
END;