我正在运行这个查询,它正在填充我的临时表,然后我从中导出。 priceSingle是通过简单地加倍票价来计算的。但是,对于某些行,该类别无论如何都是单一票价,所以我不想加倍。该查询实际上嵌入在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
?
答案 0 :(得分:5)
CASE WHEN category = 5 OR category = 10 THEN fare ELSE fare * 2 END