select查询结果新增字段并指定值

2018-11-27  本文已影响0人  比博

原表 :

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)

查询结果1 :

mysql> select * from user;
+----+------+
| id | name |
+----+------+
|  1 | abc  |
|  2 | xyz  |
+----+------+
2 rows in set (0.00 sec)

查询结果返回新增is_person字段, 且结果为"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的左边为新增字段固定值,右边为新增字段的字段名,如果固定值为数值型则不用加引号,固定值为其他类型则必须加引号。




原文链接

上一篇下一篇

猜你喜欢

热点阅读