0

I'd like to do

SELECT column1 + column2 as add_of_two_columns
    , add_of_two_columns + column3 as another_add_of_two_columns 
FROM table1 
ORDER BY (add_of_two_columns * 2) / another_add_of_two_columns;

Unfortunately, I get errors in my SELECT clause and in my ORDER clause that columns (my aliases) don't exist.

How can I make this work?

Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275
Mohamed El Mahallawy
  • 13,024
  • 13
  • 52
  • 84
  • 1
    [PostgreSQL: using a calculated column in the same query](https://stackoverflow.com/a/36530228/5070879) Subquery or duplicating expression or `LATERAL JOIN`. Feel free to choose the one that suits you best – Lukasz Szozda May 06 '18 at 07:00
  • Explanation why you can't use both at the same level: [All-at-Once Operations](https://social.technet.microsoft.com/wiki/contents/articles/20724.all-at-once-operations-in-t-sql.aspx#All-at-Once) – Lukasz Szozda May 06 '18 at 07:06

0 Answers0