如何用SQL偏移表列?

时间:2015-10-08 17:06:02

标签: mysql sql

我想使用它以前的值修改表格列中的值。目前我使用以下两个命令:

SET @bal = (SELECT balance FROM customers WHERE id = @id) - @amount;
UPDATE customers SET balance = @bal WHERE id = @id;

我能用一句话来做吗?

1 个答案:

答案 0 :(得分:0)

UPDATE customers 
SET balance = balance - @amount
WHERE id = @id;