MySQL MySQL选择返回一个虚拟列?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1539121/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL select that returns a dummy column?
提问by An employee
Is there a way i can do a SELECT and tell it to return 3 columns and a dummy empty column ? I need 4 columns and the 3rd must be '' until the table is somewhere in the database. I am not allowed to add any columns to any tables.
有没有办法我可以做一个 SELECT 并告诉它返回 3 列和一个虚拟空列?我需要 4 列,第三列必须是 '' 直到表位于数据库中的某个位置。我不允许向任何表添加任何列。
回答by Sean Vieira
Select column1, column2, 'waiting for table' as dummy_column, column4
from your_table
回答by Dan Carley
mysql> SELECT '' AS empty_col;
+-----------+
| empty_col |
+-----------+
| |
+-----------+
1 row in set (0.00 sec)
回答by SeriousCallersOnly
Use for a column with empty string
用于带有空字符串的列
Select column1, column2, '' as dummy_col, column 4
from your_table
or for a column with a Null value
或对于具有 Null 值的列
Select column1, column2, Null as dummy_col, column 4
from your_table
回答by SSS
If you want to add a dummy column and keep the column rows empty you should use this instead:
如果您想添加一个虚拟列并将列行保持为空,您应该使用它:
Select column1, column2, '' as dummy_column, column4
from your_table
This will add an empty column called dummy_column; whatever is populated in-between the quotation marks ''
is what what will appear as the dummy column's value.
这将添加一个名为 dummy_column 的空列;在引号之间填充的''
内容将显示为虚拟列的值。