I have the following query:
select
title,
( stock_one + stock_two ) as global_stock
from product
order by
global_stock = 0,
title;
Running it in PostgreSQL 8.1.23 i get this error:
Query failed: ERROR: column "global_stock" does not exist
Anybody can help me to put it to work? I need the availale items first, after them the unnavailable items. Many thanks!
You can always
ORDER BY
this way:or wrap it in another SELECT:
On solution is to use the position:
However, the alias should work, but not necessarily the expression. What do you mean by "global_stock = 0"? Do you mean the following: