我们首先创建一个具有ENUM类型列的表-
mysql> create table DemoTable( isMarried ENUM('1','0') );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('0'); mysql> insert into DemoTable values('1'); mysql> insert into DemoTable values('1'); mysql> insert into DemoTable values('0'); mysql> insert into DemoTable values('0'); mysql> insert into DemoTable values('1'); mysql> insert into DemoTable values('0');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-----------+ | isMarried | +-----------+ | 0 | | 1 | | 1 | | 0 | | 0 | | 1 | | 0 | +-----------+ 7 rows in set (0.00 sec)
以下是查询,其中我们对引用的值进行计数,即插入“ 0”的记录-
mysql> select count(*) from DemoTable where isMarried='0';
这将产生以下输出-
+----------+ | count(*) | +----------+ | 4 | +----------+ 1 row in set (0.06 sec)