Jaigus Jaigus - 13 days ago 6
SQL Question

How can I create a temporary column as the result of arithmetic from two other columns?

I want to acheive the following:

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

Answer

Your syntax isn't far off, try this:

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

The general ANSI syntax for aliasing a column is:

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