简体   繁体   English

MySQL SELECT包含一个包含字符串的额外列

[英]MySQL SELECT with an extra column containing a string

I used to know how to do this, but I can't seem to remember or find the answer. 我曾经知道如何做到这一点,但我似乎无法记住或找到答案。

I want to return data from a table and then just add an extra column with a set value (which does not need to be saved). 我想从表中返回数据,然后只添加一个带有设置值的额外列(不需要保存)。 So, it is not an UPDATE issue. 所以,它不是UPDATE问题。 Just a SELECT with that extra column. 只是带有额外列的SELECT

Original table: 原表:

|  id  |   col1   |   col2   |
|  1   |  value1  |  value2  |

Return something like this: 返回这样的东西:

|  id  |   col1   |   col2   ||    tmpCol    |
|  1   |  value1  |  value2  ||    12:48     |

它很简单:

SELECT id, col1, col2, '12:48' AS tempCol

用这个

select id,col1,col2, '12.48'  as tempcol

try this. 尝试这个。 alter table TableName add column columnName date ; alter table TableName add column columnName date; note, put the exact table name in the "TableName that i defined" that u want to add the column and put the column name where i defined the "columnName" 注意,将确切的表名放在我想要添加列的“我定义的TableName”中,并将列名放在我定义的“columnName”中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM