mysql update和case语句结合

做数据库重构之后做数据导入需要将字符串转换为int类型,转换的情况太多于是采用了update和case语句结合,果然省了很多的SQL

UPDATE test
SET avg_discount_area = (
    CASE
    WHEN avg_discount_area ='9.5折以上' THEN 0
WHEN avg_discount_area ='(8.0~8.5)折' THEN 1
WHEN avg_discount_area ='(6.5~8.0)折' THEN  2
WHEN avg_discount_area ='(4.0~6.5)折' THEN 3
WHEN avg_discount_area='(2.5~4.0)折' THEN 4
WHEN avg_discount_area='(1.0~2.5折)' THEN 5
WHEN avg_discount_area = '1折以下' THEN 6
WHEN avg_discount_area = '无数据' THEN 7
END
);

你可能感兴趣的:(mysql基本操作)