SQLite - 将值增加一定数量 [英] SQLite - increase value by a certain number
本文介绍了SQLite - 将值增加一定数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在不读取最后一个值然后更新它的情况下将表中的某个值增加某个数字?
is it possible to increase a certain value in a table by a certain number without reading last value and afterwards updating it?
即我有产品"和质量"列:产品: iLamp质量:50
i.e. I have columns "product" and "quality": product: iLamp quality: 50
我想将质量提高(或降低)x.为此,我首先读取最后一个值 (50),增加或减少它,然后将其写回.
I want to increase(or decrease) quality by x. To achieve this I am first reading last value (50), increasing or decreasing it, and writing it back.
有没有直接的方法来完成这个任务?
Is there a direct way to complete this task?
推荐答案
示例 1(适用于所有行):
UPDATE Products SET Price = Price + 50
示例 2(针对特定行):
UPDATE Products SET Price = Price + 50 WHERE ProductID = 1
示例 3(通用):
UPDATE {Table} SET {Column} = {Column} + {Value} WHERE {Condition}
地点:
{Table}
- 表名{Column}
- 列名{Value}
- 列值应增加或减少的数字{Condition}
- 某些条件(如果有)
{Table}
- table name{Column}
- column name{Value}
- a number by which column's value should be increased or decreased{Condition}
- some condition if any
这篇关于SQLite - 将值增加一定数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文