使用 MySQL 中的 ENUM 字段选择行
mysqlmysqli database更新于 2025/8/3 11:56:17
首先我们创建一个表 −
mysql> create table DemoTable
-> (
-> EmployeeStatus ENUM('FULLTIME','Intern') default NULL
-> );
Query OK, 0 rows affected (0.66 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable values('FULLTIME');
Query OK, 1 row affected (0.19 sec)
mysql> insert into DemoTable values('Intern');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable values('Intern');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable values();
Query OK, 1 row affected (0.12 sec)
使用 select 语句显示表中的所有记录 −
mysql> select * from DemoTable;
这将产生以下输出 −
+----------------+ | EmployeeStatus | +----------------+ | FULLTIME | | Intern | | Intern | | NULL | +----------------+ 4 rows in set (0.00 sec)
这是使用 MySQL 中的 ENUM 字段选择行的查询 −
mysql> select * from DemoTable -> where EmployeeStatus is null or EmployeeStatus <> 'Intern';
这将产生以下输出 −
+----------------+ | EmployeeStatus | +----------------+ | FULLTIME | | NULL | +----------------+ 2 rows in set (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

