mysql> select * from user; +----+------+------+ | id | name | sex | +----+------+------+ | 1 | 张三 | 1 | | 2 | 李四 | 1 | | 3 | 张珊 | 0 | +----+------+------+ 3 rows in set (0.00 sec)
使用 when 和 zhen end 对查询字段进行格式化
mysql> select id, name, case sex when 1 then '男' when 0 then '女' end from user; +----+------+------------------------------------------------+ | id | name | case sex when 1 then '男' when 0 then '女' end | +----+------+------------------------------------------------+ | 1 | 张三 | 男 | | 2 | 李四 | 男 | | 3 | 张珊 | 女 | +----+------+------------------------------------------------+ 3 rows in set (0.00 sec)
对格式化内容重新命名
mysql> select id, name, case sex when 1 then '男' when 0 then '女' end as '性别' from user; +----+------+------+ | id | name | 性别 | +----+------+------+ | 1 | 张三 | 男 | | 2 | 李四 | 男 | | 3 | 张珊 | 女 | +----+------+------+ 3 rows in set (0.00 sec)
标签:格式化,name,end,when,mysql,+----+------+------+,id From: https://www.cnblogs.com/fmg0224/p/17167543.html