How I get OR to SUM(IF()) MySQL

2019-08-05 16:19发布

i have a problem. I need to find out, how to put OR in this order:

SELECT ROUND(o.`total_products`  / c.`conversion_rate` - 
           (SUM(IF(pa.wholesale_price = "0" , p.wholesale_price, 
           pa.wholesale_price)*od.product_quantity)))

And I need to put OR together with "0" like this:

SELECT ROUND(o.`total_products`  / c.`conversion_rate` - 
           (SUM(IF(pa.wholesale_price = "0" OR "IS NULL", p.wholesale_price, 
           pa.wholesale_price)*od.product_quantity)))

I want this result: If pa.wholesale_price is zero or row does not exist, use p.wholesale_price. If pa.wholesale_price exist, use pa.wholesale_price.

Can anybody help me?

2条回答
你好瞎i
2楼-- · 2019-08-05 16:38
IF(pa.wholesale_price = 0 OR pa.wholesale_price IS NULL, 
          p.wholesale_price, pa.wholesale_price)

or shorter:

IF(coalesce(pa.wholesale_price,0) = 0, p.wholesale_price, pa.wholesale_price)
查看更多
时光不老,我们不散
3楼-- · 2019-08-05 17:00

try

IF((pa.wholesale_price = "0") OR (pa.wholesale_price IS NULL)......

查看更多
登录 后发表回答