【问题标题】:How can i modify this sql for execute?如何修改此 sql 以执行?
【发布时间】:2017-08-02 05:28:36
【问题描述】:

创建表钱包(userId int , coin int, 主键(userId));

更新钱包 SET coin=coin-(least(select coin FROM wallet where userId=101,500)) where userId=101;

【问题讨论】:

  • 你想做什么?运行它?
  • 我认为使用“钱包”和“硬币”的人不应该问这种问题。
  • 这个 sql 有语法错误,但我想不通。
  • 语法错误是,500应该在括号之后

标签: mysql sql


【解决方案1】:

一个

update wallet 
SET coin=coin-(least(coin,500)) 
where userId=101;

或者其他的可能

update wallet 
SET coin=case when coin < 500 then 0 else coin-500 end
where userId=101;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-08
    • 1970-01-01
    • 2021-03-08
    • 2023-04-02
    • 1970-01-01
    • 2021-09-17
    • 2019-06-12
    • 2011-12-29
    相关资源
    最近更新 更多