if语句的mysql语法问题

时间:2013-04-09 15:56:20

标签: mysql phpmyadmin syntax-error

我在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"

1 个答案:

答案 0 :(得分: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