sql语句常用功能(null值转换为0)

COALESCE(规格,' ')

或者

COALESCE(规格,0)

 

select *
from (
SELECT p2.name_template 产品, p3.pname 材料 ,p3.spec 尺寸,(select c2.name from product_part_info c1 LEFT JOIN res_huo c2 ON c1.hpartner_id=c2.id where p3.id=c1.product_tmpl_id order by c1.id limit 1) 客户,(select khwl_code from product_custo_info where p3.id=product_tmpl_id order by id limit 1) 物料号,p4.name 内部批次,p4.outsidename 外部批次,p1.库存,p5.总库存
FROM (SELECT SUM(qty) 存量,product_id,lot_id
FROM stock_kqty p1
WHERE location_id=${仓}
GROUP BY product_id,lot_id) p1
LEFT JOIN product_code p2 ON p2.id=p1.product_id
LEFT JOIN  product_tep p3 ON p3.id =p2.product_tmpl_id
LEFT JOIN stock_pci_lot p4 ON p4.id=p1.lot_id
LEFT JOIN (SELECT SUM(qty) 总存量,product_id
FROM stock_kqty p1
WHERE location_id=${仓}
GROUP BY product_id
) p5 ON p2.id=p5.product_id
) abc
where (产品 like'%${产品}%' or COALESCE(材料,'') like '%${产品}%' or COALESCE(尺寸,'') like '%${产品}%' ) and (客户 like '%${客户}%' or 客户 is null ) and 库存<>0
;

 

posted @ 2018-01-21 16:19  何双新  阅读(9845)  评论(0编辑  收藏  举报