我有两个表有一个相同的列名,但数据不同.我想加入表,但访问两列(row ["price"],row ["other_price"]):如何在select语句中重命名/别名?(我不想在DB中重命名它们)
MrT*_*lly 43
选择table1.price,table2.price作为other_price .....
Mat*_*att 16
select t1.Column as Price, t2.Column as Other_Price
from table1 as t1 INNER JOIN table2 as t2
ON t1.Key = t2.Key
Run Code Online (Sandbox Code Playgroud)
像这样 ?
我们AS关键字
select a.Price as PriceOne, b.price as PriceTwo
from tablea a, tableb b
Run Code Online (Sandbox Code Playgroud)
如果像我一样,您正在对一列执行此操作,然后该列将经过 COALESCE / array_to_json / ARRAY_AGG / row_to_json (PostgreSQL) 并希望在列名称中保留大写字母,请双引号列名称,如下所示:
SELECT a.price AS "myFirstPrice", b.price AS "mySecondPrice"
Run Code Online (Sandbox Code Playgroud)
如果没有引号(以及使用这些函数时),我的驼峰命名法中的列名称将丢失大写字母。