在MySQL中添加一个带有值的临时列?
您可以借助以下语法添加具有值的临时列-
select yourColumnName1,yourColumnName2,.....N ,yourTemporaryColumnValue as yourTemporaryColumnName from yourTableName;
要添加一个带有值的临时列,让我们创建一个表。以下是查询-
mysql> create table TemporaryColumnWithValueDemo−> (
−> StudentId int,
−> StudentName varchar(100)
−> );
在表中插入一些记录。插入记录的查询如下-
mysql> insert into TemporaryColumnWithValueDemo values(101,'John');mysql> insert into TemporaryColumnWithValueDemo values(102,'Johnson');
mysql> insert into TemporaryColumnWithValueDemo values(103,'Carol');
mysql> insert into TemporaryColumnWithValueDemo values(104,'Sam');
显示上面插入的所有记录。显示所有记录的查询如下-
mysql> select *from TemporaryColumnWithValueDemo;
以下是输出-
+-----------+-------------+| StudentId | StudentName |
+-----------+-------------+
| 101 | John |
| 102 | Johnson |
| 103 | Carol |
| 104 | Sam |
+-----------+-------------+
4 rows in set (0.00 sec)
现在,这里是添加带有t.emporary值的列的查询。查询如下-
mysql> select StudentId,StudentName,'M.I.T.' as TempCollegeName from TemporaryColumnWithValueDemo;
以下是输出。临时列已成功添加-
+-----------+-------------+-----------------+| StudentId | StudentName | TempCollegeName |
+-----------+-------------+-----------------+
| 101 | John | M.I.T. |
| 102 | Johnson | M.I.T. |
| 103 | Carol | M.I.T. |
| 104 | Sam | M.I.T. |
+-----------+-------------+-----------------+
4 rows in set (0.00 sec)
以上是 在MySQL中添加一个带有值的临时列? 的全部内容, 来源链接: utcz.com/z/353512.html