1

我在 if 语句附近遇到了这种语法的问题,我不断检查附近的 mysql 语法

== 'purp1' and product_price==53, 13, 0) as ShipWeight  

这就是我想要完成的。有任何想法吗?

select wp_cart66_order_items.order_id as Order_ID,
   wp_cart66_orders.trans_id as Order_Number,
   wp_cart66_orders.bill_first_name as Bill_First_Name,   
   wp_cart66_orders.bill_last_name as Bill_Last_Name,
   wp_cart66_orders.ship_first_name as Ship_First_Name,
   wp_cart66_orders.ship_last_name as Ship_Last_Name,
   wp_cart66_orders.ship_address as Ship_Address1,
   wp_cart66_orders.ship_address2 as Ship_Address2,
   wp_cart66_orders.ship_city as Ship_City,
   wp_cart66_orders.ship_state as Ship_State,
   wp_cart66_orders.ship_zip as Ship_zip,
   wp_cart66_order_items.item_number as Item_Number,
   wp_cart66_order_items.product_price as Price,
   wp_cart66_order_items.Description as OrderItemsDescription,
if(item_number == 'purp1' and product_price==53, 13, 0) as ShipWeight
from wp_cart66_orders 
inner join wp_cart66_order_items
    on wp_cart66_orders.id=wp_cart66_order_items.order_id 
where wp_cart66_orders.ordered_on between "2013-04-01 00:00:00" and "2013-04-02 23:59:59"
4

1 回答 1

0

在浏览文档时,我找不到 mysql 是否支持==,请尝试将其更改为=

if(item_number = 'purp1' and product_price=53, 13, 0) as ShipWeight

更新 1

采用CASE()

CASE 
    WHEN item_number = 'marley1' and product_price='12.00' THEN 2
    WHEN item_number = 'samp1' and product_price='19.50' THEN 4
    ELSE 0
END ShipWeight
于 2013-04-09T15:57:31.027 回答