我有一个包含少量列的表,其中一列名为_bandwidth,其中的值为十进制.
所以我想键入一个sql查询,将值添加到现有值.
假设用户ID 1的_bandwidth的值是150.000并且我想为这个值加200,所以总和将是350.000
这是我输入的查询,但它不起作用.
update users set _bandwidth = (select _bandiwdth from users where _ID = 1) + 150 where _ID = 1
Run Code Online (Sandbox Code Playgroud)
也做了类似的事情:
update users set _bandwidth += 200 where _ID = 1
Run Code Online (Sandbox Code Playgroud)
当然他们错了,但我希望你明白我想要达到的目标.
非常感谢提前.
编辑 找到解决方案,答案是:
update users set _bandwidth = _bandwidth + 200 where _ID = 1
Run Code Online (Sandbox Code Playgroud)
小智 8
UPDATE Users
SET _bandwidth = _bandwidth + 200
WHERE _ID =1
Run Code Online (Sandbox Code Playgroud)
会工作
update users
set _bandwidth = _bandiwdth + 200
where _ID = 1
Run Code Online (Sandbox Code Playgroud)