2017-08-02 27 views
-5

create table wallet(userId int,coin int,primary key(userId));我如何修改这个sql执行?

更新钱包SET硬币=硬币 - (最少(选择硬币从钱包其中userId = 101,500))其中userId = 101;

+1

你想要做什么?只是运行它? – Steven

+0

我不认为这是一个与“钱包”和“硬币”工作的人应该问的那种问题。 – user3791372

+0

这个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;