MySQL 查询选择 ENUM('M', 'F') 作为 'Male' 或 'Female'?
您可以IF()为此使用。让我们首先创建一个表。这里的一列是ENUM类型
mysql> create table DemoTable
(
UserId int,
UserName varchar(40),
UserGender ENUM('M','F')
);使用插入命令在表中插入记录-
mysql> insert into DemoTable values(1,'John','M'); mysql> insert into DemoTable values(2,'Maria','F'); mysql> insert into DemoTable values(3,'David','M'); mysql> insert into DemoTable values(4,'Emma','F');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+--------+----------+------------+ | UserId | UserName | UserGender | +--------+----------+------------+ | 1 | John | M | | 2 | Maria | F | | 3 | David | M | | 4 | Emma | F | +--------+----------+------------+ 4 rows in set (0.00 sec)
以下是选择ENUM('M','F')作为'Male'或'Female'的查询-
mysql> SELECT UserId,UserName,IF(UserGender='F','Female', 'Male') AS `UserGender` from DemoTable;
+--------+----------+------------+ | UserId | UserName | UserGender | +--------+----------+------------+ | 1 | John | Male | | 2 | Maria | Female | | 3 | David | Male | | 4 | Emma | Female | +--------+----------+------------+ 4 rows in set (0.00 sec)
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下