我想根据作业类型
更新我的client
数据库
id Job_type Meal_Ticket
---------------------------
1 x 20
2 2x 12
意思是如果我点击按钮点击添加20张餐票,它应该更新为:
id Job_type Meal_Ticket
----------------------------
1 x 40
2 2x 52
我试过
UPDATE Staff
SET Rticket = CASE
WHEN Jobtype = 'x' THEN Rticket = SUM(Rticket + 20)
WHEN Jobtype = '2x' THEN Rticket = SUM(Rticket + 2*20)
ELSE Rticket
END
答案 0 :(得分:1)
我想你想要这个:
UPDATE Staff
SET Rticket = CASE WHEN Jobtype = 'x' THEN Rticket + 20
WHEN Jobtype = '2x' THEN Rticket + 40 END
WHERE Jobtype IN ('x', '2x');
我在您的逻辑中看到的唯一问题是,当您应该使用SUM
运算符时,您正在使用+
添加两个数量。