0
INSERT INTO orders_total SET `title`='Discount Coupon:', `text` = '-$40.00', `value` = '40.00' WHERE `orders_id` = '15474' AND `class`='ot_coupon

它给出了以下mysql错误:

#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 'WHERE `orders_id` = '15474' AND `class`='ot_coupon'' at line 1

知道我做错了什么吗?

4

1 回答 1

4

INSERT语句旨在插入新行,现在更新现有行,WHERE因此子句在INSERT. 你打算UPDATE

UPDATE orders_total
SET 
  `title`='Discount Coupon:', 
  `text` = '-$40.00', 
  `value` = '40.00'
WHERE 
  `orders_id` = '15474' 
  AND `class`='ot_coupon'

评论后编辑:

如果这是为了插入而不是更新,则它不能依赖于orders_id = 15474. 如果要插入新行,则还需要插入这些值。

INSERT INTO orders_total (`orders_id`, `class`, `title`, `text`, `value`) VALUES (15474, 'ot_coupon', 'Discount Coupon:', '-$40.00', '40.00');
于 2012-06-28T12:33:52.990 回答