postgresql 添加查询中不存在的列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5605565/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-20 22:57:36  来源:igfitidea点击:

Adding A Column that doesn't exist in a query

mysqlsqlsql-serverpostgresql

提问by Devin Dixon

I want to add a column in a query that does not exist in a table and return it as a result. So lets say TABLE_TEST has column A, B and I want to return values for A, B and C. I am trying to do

我想在表中不存在的查询中添加一列并将其作为结果返回。所以让我们说 TABLE_TEST 有 A、B 列,我想返回 A、B 和 C 的值。我正在尝试做

SELECT A, B, C=3 FROM TABLE_TEST

or

或者

SELECT *, C=3 FROM TABLE_TEST

Can this be done in MySQL, Postgresel or MSSQL?

这可以在 MySQL、Postgresel 或 MSSQL 中完成吗?

回答by Pablo Santa Cruz

Yes, sure:

是的,当然:

select a, b, 3 as c from table_test

That's it. It works on three db engines you've mentioned.

而已。它适用于您提到的三个数据库引擎。

回答by Marco

You should use:

你应该使用:

SELECT A,B, 3 AS C FROM TABLE_TEST

回答by anishMarokey

you can use as

你可以用作

Select a,b, 3 as c from table

This is known as alias

这被称为 alias