原表 :
mysql> desc user;
+-------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | char(30) | NO | | NULL | |
+-------+----------+------+-----+---------+----------------+
2 rows in set (0.01 sec)
查詢結(jié)果1 :
mysql> select * from user;
+----+------+
| id | name |
+----+------+
| 1 | abc |
| 2 | xyz |
+----+------+
2 rows in set (0.00 sec)
查詢結(jié)果返回新增is_person字段, 且結(jié)果為"true" :
mysql> select *,"true" as is_person from user;
+----+------+-----------+
| id | name | is_person |
+----+------+-----------+
| 1 | abc | true |
| 2 | xyz | true |
+----+------+-----------+
2 rows in set (0.00 sec)
as的左邊為新增字段固定值,右邊為新增字段的字段名,如果固定值為數(shù)值型則不用加引號,固定值為其他類型則必須加引號。
原文鏈接