mysql第一弹(case_when)

数据表结构:


数据表结构

数据表数据:


数据表数据

查询效果:
查询效果

SQL语句:

SELECT
    update_type,
    ( CASE update_type WHEN 1 THEN "名称" WHEN 2 THEN "编码" WHEN 3 THEN "所属地" END ) AS update_typename,
    ( CASE update_type WHEN 1 THEN before_name WHEN 2 THEN before_code WHEN 3 THEN before_belong END ) AS before_update,
    ( CASE update_type WHEN 1 THEN after_name WHEN 2 THEN after_code WHEN 3 THEN after_belong END ) AS after_update 
FROM
    pch_case
//case···when···语法
CASE case_value
    WHEN when_value THEN
        statement_list
    ELSE
        statement_list
END CASE;

你可能感兴趣的:(mysql第一弹(case_when))