Reputation: 32321
I am using mysql
I have a query as shown below
Select
cost,
(service_charge*(cost-Discount)) as service_charge,
(service_tax*(cost-Discount+(service_charge*(cost-Discount)))) as service_tax
From VENDOR_ITEMS
WHERE vendor_items_id = 264
My question is that the value i get as service_charge
can i use that in the calculation of service_tax
??
Please let me know if this is possible
Upvotes: 0
Views: 38
Reputation: 49049
You cannot use a computed value to calculate another, but you can use variables:
SELECT
cost,
@sc := (service_charge*(cost-Discount)) as service_charge,
(service_tax*(cost-Discount+( @sc ))) as service_tax
FROM
VENDOR_ITEMS
WHERE
vendor_items_id = 264
Upvotes: 2
Reputation: 26784
You have to repeat the expression
Select cost ,
(service_charge*(cost-Discount)) as service_charge ,
(service_tax*(cost-Discount+((service_charge*(cost-Discount))*(cost-Discount)))) as service_tax
From VENDOR_ITEMS WHERE vendor_items_id = 264
Upvotes: 0