我正在使用mysql
我有一个查询,如下所示
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
我的问题是我得到service_charge
的值我可以在计算service_tax
时使用它吗?
如果可能,请告诉我
答案 0 :(得分:2)
您不能使用计算值来计算另一个,但您可以使用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
答案 1 :(得分:0)
你必须重复表达
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