SQL update語句加減乘除運算


在處理提現操作時,遇到這樣一個問題:account_money為用戶剩余金額,提現之后要減去相應金額,需要用update語句進行運算,記錄一下

update之前數據庫數據(下邊所有的數據演示都是與前一步數據進行對比)

  

1、減法:

update money_user_bank set account_money=account_money-100 where id=1

  結果:

  

2、加法:

1 update money_user_bank set account_money=account_money+100 where id=1

  結果:

  

3、除法:

1 update money_user_bank set account_money=account_money/10 where id=1

  結果:

  

4、乘法:

update money_user_bank set account_money=account_money*10 where id=1

  結果:

  

5、如果要對整列進行操作則 '不加where' 條件即可,這里只演示加法,其他都一樣。

1 update money_user_bank set account_money=account_money+1000

 

  結果: 

  

 

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM