douchen2595 2012-04-27 14:59
浏览 12
已采纳

如果另一个字段等于5或10,则不要乘以字段

I'm running this query which is populating my temp table which I then export from. The priceSingle is calculated by simply doubling the fare. However, for some rows, the category is a single fare anyway, so I don't want to double it. The query is actually embedded in a string in PHP, but the SQL looks like:

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'

How can I avoid doing fare*2 when category equals 5 or 10?

  • 写回答

1条回答 默认 最新

  • douxiexie3574 2012-04-27 15:01
    关注
    CASE WHEN category = 5 OR category = 10 THEN fare ELSE fare * 2 END
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端