DB2 将值增加一定量
我需要编写一个查询,在运行时将表中的值增加 3。
我想做这样的事情,但这行不通。
更新表 设置值=(选择值 从表 WHERE 条件 = true) + 3
WHERE 条件 = true
正如标题所示,这是一个 DB2 数据库,有什么想法吗?
编辑:实际上这确实有效,也可以在选择中执行+ 3。我只是把一些东西放在了我必须做的选角的错误地方 提前致谢
I need to write a query that increments a value in a table by 3 when run.
I would like to do something like this but this doesn't work.
UPDATE table
SET value = (SELECT value
FROM table
WHERE condition = true) + 3
WHERE condition = true
As in the title this is a DB2 database, any ideas?
EDIT: Actually this does work, could also do the + 3 in the select. I just had some stuff in the wrong place with the casting I had to do
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您正在寻找的只是
这有效吗?
如果您希望条件 = true 的所有行都具有(例如)3+ 条件为 true 的任何行的最大值,请使用以下命令:
I think what you are looking for is simply
Does that work?
If you want all rows where condition = true to have (for example) 3+ the max value of any row for which the condition is true, use this: