Mysql CASE ELSE END 例子

SELECT
  CAST(
    SUM(
      CASE orders.currency
        WHEN 'EUR' THEN ((orders.unit_price * assignings.quantity) * 1.4)
        WHEN 'CNY' THEN ((orders.unit_price * assignings.quantity) / 6.8)
        ELSE (orders.unit_price * assignings.quantity)
      END
    ) AS decimal(10, 1)
  ) `sum_amount`
FROM assignings, orders

你可能感兴趣的:(mysql)