获取上述错误。
我尝试将while循环中的wheres切换为haves,但是没有运气。我不知道是否在while循环中正在破坏事物还是什么?
目标是使用equip_ava temp表中存储的数据来赌一张包含可用物品的表格,并根据发票是否减去该物品而减去。
BEGIN
DECLARE s int(5);
DECLARE m int(5);
DECLARE o date;
DECLARE i date;
DECLARE a int(3);
DECLARE e int(3);
DROP TABLE IF EXISTS equip_out;
CREATE TEMPORARY TABLE equip_out
SELECT line_items.invoice_number,date_out,date_due_in,equipment_qty,line_items.equipment_id FROM invoices join line_items
group by Sequence;
DROP TABLE IF EXISTS equip_ava;
CREATE TEMPORARY TABLE equip_ava
SELECT equipment_id,equipment_total FROM equipment
GROUP BY equipment_id;
SET @s = 1;
SET @m = MAX(line_items.Sequence);
WHILE @s <= @m DO
SELECT date_out INTO @o FROM invoices join line_items
WHERE Sequence=@s
GROUP BY Sequence;
SELECT date_due_in INTO @i FROM invoices join line_items
WHERE Sequence=@s
GROUP BY Sequence;
IF daily BETWEEN @o AND @i THEN
SELECT equipment_qty INTO @a FROM line_items
WHERE Sequence=@s
GROUP BY Sequence;
SELECT equipment_id INTO @e FROM line_items
WHERE Sequence=@s
GROUP BY Sequence;
UPDATE equip_ava
SET equipment_total=equipment_total-@a
WHERE equipment_id=@e;
END IF;
SET @s=@s+1;
END WHILE;
SELECT * FROM equip_ava;
END
答案 0 :(得分:0)
发现问题需要更改
SET @m = MAX(line_items.Sequence);
到
SELECT @m = MAX(line_items.Sequence) FROM line_items;
答案 1 :(得分:0)
您不能在存储过程(或任何SET
语句)中直接使用聚合函数;它必须是SELECT
的一部分。您需要将该行更改为
SET @m = (SELECT MAX(Sequence) FROM line_items);
或
SELECT MAX(Sequence) INTO @m FROM line_items;
请注意,您已经声明了很多变量,但实际上并未使用它们。 @s
是全局变量,s
是过程中的局部变量。