需求
维护表数据:
1、当pm字段值小于24时,将其值设为6;
2、当pm字段值大于24 AND 小于36时,将其值设为24;
3、当前值大于36,将其值设为36。
SQL
一、多次修改
#pm<24 pm设为6
UPDATE tb_weekly_plan SET pm = 6 WHERE pm + 0 < 24;
#24<pm<36 pm设为24
UPDATE tb_weekly_plan SET pm = 24 WHERE pm + 0 > 24 AND pm + 0 < 36;
#36<pm pm设为36
UPDATE tb_weekly_plan SET pm = 36 WHERE pm + 0 > 36;
二、CASE WHEN TEHN ELSE END
#CASE WHEN THEN ELSE END
UPDATE tb_weekly_plan SET pm = CASE
WHEN pm + 0 < 24 THEN 6
WHEN pm + 0 > 24 AND pm + 0 < 36 THEN 24
ELSE 36
END;
三、IF、ELSEIF、ELSE怎么写???求解
#附上某次尝试代码
UPDATE tb_weekly_plan SET pm =
IF pm + 0 < 24 THEN 6
ELSEIF pm + 0 > 24 AND pm + 0 < 36 THEN 24
ELSE THEN 36;