程序是:
BEGIN DECLARE v_user_id INT DEFAULT 0; DECLARE v_order_id INT DEFAULT 0; DECLARE v_min_price INT DEFAULT 0; UPDATE `ordersperformers` SET `ordersperformers`.`Status` = 1 WHERE EXISTS ( SELECT @v_min_price = MIN(`ordersperformers`.`DeliveryPrice` + `ordersperformers`.`Price`), @v_user_id = `ordersperformers`.`Users_Id` = @v_user_id, @v_order_id =`ordersperformers`.`Orders_Id` FROM `ordersperformers` INNER JOIN `orders` ON `orders`.`Id` = `ordersperformers`.`Orders_Id` WHERE NOW() <= DATE_SUB(`orders`.`DeliveryDate`, INTERVAL 2 HOUR) AND `orders`.`Status` = 0 AND `ordersperformers`.`Status` = 0 ) AND `ordersperformers`.`Orders_Id` = @v_order_id AND `ordersperformers`.`Users_Id` = @v_user_id; END
如何解决?
我认为您想要一个相关的子查询:
UPDATE ordersperformers op SET op.Status = 1 WHERE op.Status = 0 AND op.Orders_Id = @v_order_id AND op.Users_Id = @v_user_id AND EXISTS (SELECT 1 FROM orders o WHERE o.id = op.Orders_Id AND NOW() <= DATE_SUB(o.DeliveryDate, INTERVAL 2 HOUR) AND o.Status = 0 );
我更改/修复了其他一些问题:
WHERE
EXISTS
SELECT