I have this query:
SELECT
((ms.ActualQuantityDeliveredinSalesUnits / od.CumulativeOrderQuantityInSalesUnits)*od.NetValueOfTheOrderItemInDocumentCurrency)-inv.NetValueOfTheBillingItemInDocumentCurrency AS ENRUTADO
,((od.CumulativeConfirmedQuantityInSalesUnit/od.CumulativeOrderQuantityInSalesUnits)*od.NetValueOfTheOrderItemInDocumentCurrency) - ENRUTADO AS CONFIRMA
,(od.CumulativeOrderQuantityInSalesUnits - od.CumulativeConfirmedQuantityInSalesUnit) * od.NetValueOfTheOrderItemInDocumentCurrency - CREDITO - HORIZONTE AS NO_CONFIRMA
,IF(od.OverallStatusOfCreditChecks = 'B' ,od.NetValueOfTheOrderItemInDocumentCurrency,0) AS CREDITO
,IF(od.OverallStatusOfCreditChecks = 'B' ,0,((IF(od.DeliveryBlock = 'ZD',1,0)*od.NetValueOfTheOrderItemInDocumentCurrency) - CREDITO)) AS HORIZONTE
FROM tb_csc_otr_orderdata` od
As you can see, in the first line I calculate the ROUTING and that calculation is the rest for the CONFIRM and later I use other calculated values. I can't think of how to use those calculated values within the same query, any ideas?
You can't use fields that the select resolves and that you give them an alias on the same row.
Option 1
Directly where it says Routed and so on with the rest, you expose what corresponds to that.
Option 2
Using a derived table or cte allows you to treat already computed columns in the output.
You'll need to rephrase the last column in order to calculate it in the output.
I can't get you any closer to the result, because you haven't posted a question with a complete reproducible scenario, plus the syntax you've pasted seems to contain errors.