我正在运行这个查询,它正在填充我的临时表,然后从中导出。单程票的价格是按车费的两倍计算的。不过,对于某些行来说,无论如何,这一类别是一种单一的票价,所以我不想加倍。查询实际上是嵌入在PHP的字符串中,但是SQL看起来像:
INSERT INTO temp
SELECT cruises.code AS sailingId, live, 'USD', 'optioncode', 'rateOptionName', '2',
category AS cabinCategory, fare*2 AS priceSingle, fare AS priceDouble,
supplements_usa.adult AS priceAdditional
FROM fares_usa, supplements_usa, cruises
WHERE fares_usa.cruise_id = supplements_usa.cruise_id
AND cruises.id = fares_usa.cruise_id AND cruises.live = 'Y'
当
fare*2
等于5或10时,如何避免执行category
? 最佳答案
CASE WHEN category = 5 OR category = 10 THEN fare ELSE fare * 2 END