开发者

Adding A Column that doesn't exist in a query

开发者 https://www.devze.com 2023-02-23 00:26 出处:网络
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

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

SELECT A, B, C=3 FROM TABLE_TEST

or

SELECT *, C=3 FROM TABLE_TEST

Can this be done in MySQL, Postgr开发者_运维技巧esel or MSSQL?


Yes, sure:

select a, b, 3 as c from table_test

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


You should use:

SELECT A,B, 3 AS C FROM TABLE_TEST


you can use as

Select a,b, 3 as c from table

This is known as alias

0

精彩评论

暂无评论...
验证码 换一张
取 消