1

我正在运行此查询,该查询正在填充我的临时表,然后从中导出。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*2category等于 5 或​​ 10时,我怎样才能避免这样做?

4

1 回答 1

5
CASE WHEN category = 5 OR category = 10 THEN fare ELSE fare * 2 END
于 2012-04-27T15:01:02.957 回答