尝试进行查询,但如果里程数为>则需要向TotalCost添加250; 150。
select milegae.dc_id,
mileage.store_id,
mileage.mileage,
round((mileage.mileage * .75 + 200),2) as TripCost
from mileage;
此查询为我提供了我想要的数据,但我不确定如何在给定参数的情况下向TotalCost添加250.
答案 0 :(得分:1)
您可以使用CASE EXPRESSION
:
select milegae.dc_id,
mileage.store_id,
mileage.mileage,
CASE WHEN mileage.mileage > 150
THEN ROUND(((mileage.mileage+250) * .75 + 200),2)
ELSE ROUND((mileage.mileage * .75 + 200),2)
END as TripCost
from mileage;
答案 1 :(得分:0)
使用CASE
表达式检查里程数> 150。
如果里程值大于250
,您希望将150
添加到最终值。
<强>查询强>
SELECT
milegae.dc_id,
mileage.store_id,
mileage.mileage,
CASE WHEN mileage.mileage > 150
THEN round((mileage.mileage * .75 + 200),2) + 250
ELSE round((mileage.mileage * .75 + 200),2)
END AS TripCost
FROM mileage;