0

我想在查询中间执行if 语句,我需要确定 oc.product_type == 'clothing' 还是 'other' 如果是服装,那么我需要选择specific_clothing表而不是non_clothing桌子?我真的输给了这个

SELECT o.total, o.shipping, o.order_date
      ,oc.product_type, oc.product_id, oc.quantity, oc.price_per
      ,cu.first_name, cu.last_name, CONCAT(cu.address1, cu.address2) AS address,

//这是我尝试使用if的地方

  if(oc.product_type = 'clothing'
      SELECT style
        FROM specific_clothing
        where oc.product_id = specific_clothing_id) as item 

    FROM order_contents AS oc
    INNER JOIN `orders` as o ON oc.order_id = o.id
    INNER JOIN `customers` AS cu ON o.customer_id=cu.id
    WHERE o.customer_id = '214';
4

1 回答 1

1

我认为您只是在考虑向specific_clothing. 像这样的东西:

SELECT o.total, o.shipping, o.order_date
      ,oc.product_type, oc.product_id, oc.quantity, oc.price_per
      ,cu.first_name, cu.last_name, CONCAT(cu.address1, cu.address2) AS address
      ,sc.style AS item

    FROM order_contents AS oc
    INNER JOIN `orders` as o ON oc.order_id = o.id
    INNER JOIN `customers` AS cu ON o.customer_id=cu.id
    LEFT OUTER JOIN specific_clothing sc ON (
        oc.product_id = sc.specific_clothing_id AND
        oc.product_type = 'clothing' )
    WHERE o.customer_id = '214';
于 2013-06-06T02:31:35.400 回答