我减去列值,但它不起作用。。
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。为什么?
最佳答案
你应该使用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
。关于mysql - 通过减去日期之间的值来更新列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39240201/