简体   繁体   English

使用 SQL 将字段值增加原始值的设定百分比

[英]Using SQL to increase a field value by a set percentage of the original value

How can i set balance to be balance + 2% (two percent of balance)我如何将余额设置为余额 + 2%(余额的 2%)

I have tried to do the following:我试图做以下事情:

UPDATE users SET balance = balance + 2 '%';

but it didn't work.但它没有用。

Also tried this:也试过这个:

UPDATE users SET balance = balance + 2%;

It still didn't work.它仍然没有工作。

Simply 2% represent 2 of 100%仅 2% 代表 100% 中的 2%

-- 2% = balance * (2/100)
UPDATE users SET balance = balance + balance * (2/100);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM