我正在编写一个应该返回浮点值的函数。
BEGIN
DECLARE due_amount DECIMAL(9,2);
SET due_amount = (SELECT due_amount FROM (
SELECT id, MAX(date), due_amount, user_id
FROM lunch_transaction
GROUP BY user_id
HAVING user_id = user) l);
IF due_amount IS NULL THEN
SET due_amount = 0.00;
END IF;
RETURN due_amount;
END
该函数仅返回值0.00
,即使该值应该是其他值。
仅运行此查询:
(SELECT due_amount FROM (
SELECT id, MAX(date), due_amount, user_id
FROM lunch_transaction
GROUP BY user_id
HAVING user_id = user) l);
虽然给出了正确的输出。
我应该如何将查询的输出设置为变量?