MySQL case when then else end 与 SUBSTRING_INDEX 例子

更新 client_and_group  表中 platform_code 字段

当 platform 字段是字符串 win32 时 platform_code = platform_code + '-W'

当 platform 字段是字符串 linux 时 platform_code = platform_code + '-L'
当 platform 字段是字符串 android 时 platform_code = platform_code + '-A'
当 platform 字段是字符串 darwin 时 platform_code = platform_code + '-M'

UPDATE client_and_group SET 
  platform_code=(CASE platform 
    WHEN 'win32' THEN CONCAT(platform_code,'-W') 
    WHEN 'linux' THEN CONCAT(platform_code,'-L') 
    WHEN 'android' THEN CONCAT(platform_code,'-A') 
    WHEN 'darwin' THEN CONCAT(platform_code,'-M') 
    ELSE platform_code END) 
  WHERE platform_code LIKE 'S%';

 

删除后缀:platform_code 字符串 - 与以后的字符串删除

UPDATE client_and_group SET platform_code=SUBSTRING_INDEX(platform_code, '-', 1);

 

posted @ 2021-07-09 14:57  aaron_agu  阅读(135)  评论(0编辑  收藏  举报