douhuai2015 2014-05-29 12:19
浏览 57
已采纳

从价格中删除金额然后插入新价格

So i have a question. I have no idea how i need to insert a search in google for it so i'm going to ask it here.

I have like 50.00 euro. in mysql table it is showed as

 Id | Username | Balance
 1  | Kev      | 50.00

Now when i buy something that is worth like lets say 5.00 euro it would be 50.00 - 5.00 = 45.00 euro left on balance

 Id | Username | Balance
 1  | Kev      | 45.00

Now my question is. How do i do this with a simply get old balance then insert the new balance into the table? Also i'm using PDO

Sorry for my nooby question but i have no idea how to insert this into a search in google.

~Kev

  • 写回答

1条回答 默认 最新

  • duanbin198788 2014-05-29 19:22
    关注

    You can update a row by setting the column equal to the current column value minus (or plus) another value

    UPDATE `table` SET `Balance` = `Balance`-5.00 WHERE `Username`='Kev' 
    

    or

    UPDATE `table` SET `Balance` = `Balance`-5.00 WHERE `Id`=1
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真