SQL 在 SELECT 中包含一个实际上不在数据库中的列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2504163/
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
Include in SELECT a column that isn't actually in the database
提问by Cypher
I'm trying to execute a SELECT statement that includes a column of a static string value. I've done this in Access, but never with raw SQL. Is this possible?
我正在尝试执行一个包含静态字符串值列的 SELECT 语句。我已经在 Access 中完成了此操作,但从未使用过原始 SQL。这可能吗?
Example:
例子:
Name | Status
------+--------
John | Unpaid
Terry | Unpaid
Joe | Unpaid
In the above example, the "Status" column doesn't exist in the database.
在上面的示例中,数据库中不存在“状态”列。
回答by Daniel Vassallo
You may want to use:
您可能想要使用:
SELECT Name, 'Unpaid' AS Status FROM table;
The SELECT
clause syntax, as defined in MSDN: SELECT Clause (Transact-SQL), is as follows:
MSDN: SELECT Clause (Transact-SQL) 中SELECT
定义的子句语法如下:
SELECT [ ALL | DISTINCT ]
[ TOP ( expression ) [ PERCENT ] [ WITH TIES ] ]
<select_list>
Where the expression
can be a constant, function, any combination of column names, constants, and functions connected by an operator or operators, or a subquery.
其中expression
可以是常量、函数、列名、常量和由一个或多个运算符连接的函数的任意组合,或子查询。