case when语句
<p>表结构</p>
<pre><code>create table if not exists test_user(
`id` bigint(20) not null AUTO_INCREMENT comment '主键自增ID',
`name` varchar(64) not null comment '姓名',
`gender` integer not null comment '性别,1: 男, 2: 女',
`country_code` integer not null comment '所属国家CODE',
primary key (`id`)
) charset = 'utf8mb4' comment '测试表';</code></pre>
<p>测试数据</p>
<pre><code>INSERT INTO `test_user` (`name`, `gender`, `country_code`)
VALUES
('清风', 1, 100),
('玄武', 2, 100),
('Kobe', 1, 110),
('John Snow', 1, 200),
('Peut-être', 0, 120);</code></pre>
<p>测试用途语句</p>
<pre><code>select `id`, `name`, `gender`, (case `gender`
when 1 then '男'
when 2 then '女'
else '未知'
end) as '性别',
`country_code`
from test_user;</code></pre>
<p>查询结果:
<img src="https://www.showdoc.cc/server/api/common/visitfile/sign/6566617a1ffc539a337f507f1a462084?showdoc=.jpg" alt="" /></p>