通过减去date之间的值来更新列

时间:2016-08-31 03:18:47

标签: mysql sql

我减去列值,但它不起作用..

avaroom

5
UPDATE `roomcalendar` 
SET avaroom = avaroom - 1 and 
day BETWEEN '2016-08-31' and '2016-08-31' and roomname='Standard Room'

当我运行此查询时。 avaroom值变为1.结果为4.为什么?

1 个答案:

答案 0 :(得分:4)

您应该使用WHERE CLAUSE

UPDATE `roomcalendar` 
SET avaroom = avaroom - 1 
WHERE day BETWEEN '2016-08-31' and '2016-08-31' and roomname='Standard Room';

模拟您的问题:

SET @avaroom := 5;

SET @avaroom := @avaroom - 1 AND 2 BETWEEN 1 AND 3;

SELECT @avaroom; Output is 1

See Demo

在将值设置为@avaroom变量之前,表达式会变为布尔值,在这种情况下,表达式始终会解析为1