I have this query:
select qa_returns_items.item_code,
(CASE status_code
WHEN 11 THEN (qa_returns_items.item_quantity - qa_returns_residues.item_quantity)
WHEN 12 THEN (qa_returns_items.item_quantity + qa_returns_residues.item_quantity) END) as total_ecuation ,
qa_returns_residues.item_unitprice,
( qa_returns_residues.item_unitprice * total_ecuation) as item_subtotal,
(qa_returns_residues.item_discount * item_quantity) as item_discount,
( ( qa_returns_residues.item_unitprice * total_ecuation) -
(qa_returns_residues.item_discount * item_quantity) ) as item_total
from qa_returns_residues, qa_returns_items
where
total_ecuation > 0
AND qa_returns_items.item_code = qa_returns_residues.item_code;
It shows me the error: Unknown column 'total_ecuation' in 'field list'
how I can use the alias as a column?