有时,为了方便起见,我们希望添加一列固定值来帮助查看MySQL中的数据,但又不希望这列出现在MySQL中。举个例子:
mysql> create table student(name varchar(20));
mysql> insert into student values('张三');
如果直接查询,结果如下:
mysq> select * from student;
+--------+
| name |
+--------+
| 张三 |
+--------+
但是,我们可以在查询时在前/后添加一行固定值方便查看:
mysql> select '2020' dt, name from student;
+------+--------+
| dt | name |
+------+--------+
| 2020 | 张三 |
+------+--------+
如果不给固定值添加别名,则:
mysql> select '2020', name from student;
+------+--------+
| 2020 | name |
+------+--------+
| 2020 | 张三 |
+------+--------+
标签:固定值,name,+------+--------+,mysql,查询,2020,student,MySQL,自定义
From: https://blog.51cto.com/u_16270487/7593583