版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_33229669/article/details/84024095
sql case when then的使用
base_dict 表中有如下的数据
如果检索的是dict_type_code, 那么可以使用case when then else end 对其再次赋值
使用case when then 检索
SELECT (case dict_type_code
when 001 then '客户行业'
WHEn 003 then '公司性质'
when 004 then '年营业额'
else '其他'
end
) type from base_dict;
检索出来的结果如下
可以看到,结果值不为code值, 而是对应的then后面的值.
对于其他没有写when的code值, 显示为其他.
注意要写end ,否则会报错.