码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2018-01-21 17:43:08      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:weight   gpo   limit   temp   log   sele   sql语句   from   code   

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
;

 

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

标签:weight   gpo   limit   temp   log   sele   sql语句   from   code   

原文地址:https://www.cnblogs.com/1314520xh/p/8323808.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!