如何在一個 MySQL 查詢中向某列新增使用者定義值?


首先建立一個表 -

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)

更新於: 2019 年 12 月 26 日

401 次瀏覽

開啟你的 職業

完成課程獲得認證

開始學習
廣告
© . All rights reserved.