如何将 +1 添加到已有值
我有一个表,其列名称为 displayorders,值为 1 到 250,并且它不是自动增量。
现在我想在表中添加一个新行,其中 displayorder
= 3。所以我不想手动将所有值从 3 更新为 250。相反,我想将所有 displayorder 更新为+1,我可以手动从1更改为2(即更新后2更改为3)。我如何通过SQL查询来做到这一点?
I have table with the column name displayorders with values 1 to 250 and it's not autoincrement.
Now I want to add a new row in table with displayorder
= 3. So I don't want to manually update all the values form 3 to 250.Instead of that I want to update all the displayorders to +1 and I can manually change from 1 to 2(ie 2 to 3 after updation).How can I do it through SQL Query?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果我理解正确,您需要运行如下的
UPDATE
语句:测试用例:
UPDATE
语句后的结果:If I understood correctly, you'd want to run an
UPDATE
statement like this:Test case:
Result after the
UPDATE
statement:更新 yourTableName set displayorder = displayorder + 1 其中 displayorder > 2
update yourTableName set displayorder = displayorder + 1 where displayorder > 2