将用户定义的值添加到 MySQL 查询中的列?
mysqlmysqli database
首先我们创建一个表 −
mysql> create table DemoTable1847 ( GameStatus ENUM('PENDING','COMPLETED','CANCELLED') ); Query OK, 0 rows affected (0.00 sec)
使用 insert 插入命令在表中插入一些记录 −
mysql> insert into DemoTable1847 values('PENDING'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1847 values('COMPLETED'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1847 values('CANCELLED'); Query OK, 1 row affected (0.00 sec)
使用 select 语句显示表中的所有记录 −
mysql> select * from DemoTable1847;
这将产生以下输出 −
+------------+ | GameStatus | +------------+ | PENDING | | COMPLETED | | CANCELLED | +------------+ 3 rows in set (0.00 sec)
这是在 MySQL 查询中向列添加用户定义值的查询
mysql> select * from DemoTable1847 union all select 'REFUND';
这将产生以下输出 −
+------------+ | GameStatus | +------------+ | PENDING | | COMPLETED | | CANCELLED | | REFUND | +------------+ 4 rows in set (0.00 sec)