当性别值作为表中的布尔值存储在表中时,将性别值提取为字符串

让我们首先创建一个表-

create table DemoTable815(Gender BOOLEAN);

使用插入命令在表中插入一些记录-

insert into DemoTable815 values(true);
insert into DemoTable815 values(false);
insert into DemoTable815 values(false);
insert into DemoTable815 values(true);

使用select语句显示表中的所有记录-

select *from DemoTable815;

这将产生以下输出-

+--------+
| Gender |
+--------+
|      1 |
|      0 |
|      0 |
|      1 |
+--------+
4 rows in set (0.00 sec)

以下是将性别作为布尔值存储在表中时将性别提取为字符串的查询-

select if(Gender=true,'MALE','FEMALE') AS String from DemoTable815;

这将产生以下输出-

+--------+
| String |
+--------+
| MALE   |
| FEMALE |
| FEMALE |
| MALE   |
+--------+
4 rows in set (0.00 sec)