I'm currently learning about SQL functions and have encountered a problem I don't know how to solve. So I'm supposed to create a function that has three parameters, a month, year and amount. It's supposed to return a count of every payment amount above the given amount and on the given date. It looks something like this now:
CREATE FUNCTION sakila.my_report(month INT, year INT, amount INT)
RETURNS INT
BEGIN
DECLARE @count INT;
DECLARE @date DATE;
SET @date = cast(@year + '-' + @month + '-00' as date);
SELECT @count = COUNT(*)
FROM payment
WHERE payment_date = @date AND payment.amount > @amount;
RETURN(@count);
END //
DELIMITER ;
This returns an error however.
[42000][1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@count INT; DECLARE @date DATE; SET @date = cast(@year + '-' +' at line 5