如何根据其他两列的算术创建临时列?

时间:2016-11-27 05:32:43

标签: sql postgresql postgresql-9.3

我想要实现以下目标:

select a, 
       b,
       diff as (b-a)
from some_table;

2 个答案:

答案 0 :(得分:1)

你的语法还不远,试试这个:

select a, 
       b,
       b - a as diff
from some_table;

列别名的通用ANSI语法是:

select <expression involving columns> as <alias name>
from some_table

答案 1 :(得分:0)

从some_table选择a,b,a-b作为差异;