[英]SQL select how to insert column name and provide value
How do you add a column to a select statement and assign a static value, when the column does not exist? 当该列不存在时,如何将其添加到select语句中并分配静态值?
name | 名称| address |
地址| vacationing |
度假 Zipcode
邮政编码
So for the example columns above, I would like to create the column on the fly of "vacationing" whose value will be assigned No for each record. 因此,对于上面的示例列,我想动态创建“休假”列,该列的值将为每个记录分配“否”。 I don't want to insert this column in the table permanently.
我不想将此列永久插入表中。
Thanks 谢谢
Do you mean something like this? 你的意思是这样吗?
SELECT Name, Address, 'No' AS Vacationing, Zipcode
FROM MyTable
select name, address, 'No' as vacationing, Zipcode from mytable;
You cannot have a column that only exists for some of the records, and not all of them. 您不能有仅对某些记录而不是对所有记录都存在的列。 Either create it permanently or if you like, create another table and JOIN it using the
name
or id
or whatever it is you use in this table as a primary key. 可以永久创建它,也可以根据需要创建另一个表并使用
name
或id
或在此表中使用的任何键作为主键来联接它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.