2017-08-02 29 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;