我的代码是在一定的日期范围内知道我的库存状态,但是我遇到问题,当涉及到库存时它没有返回值。
我在套头衫中没有任何值仍然应该计算股票=已交付 - (已售出+已推出) 这是代码。
Select A.prod_name As Product, A.prod_totalPrice As Price, A.prod_category As Category, A.prod_ExpDate As Expiration,
ifnull((Select SUM(itp_needQty) from tbl_itmonpur Where itp_prodID = (Select prod_id from tbl_prod where prod_name = A.prod_name)and itp_statusDelv = 'DELIVERED' and itp_date Between "10/06/2014" and "10/06/2014"),0) As Delivered,
ifnull((Select SUM(sales_qty) from tbl_sales Where sales_prodID = (Select prod_id from tbl_prod where prod_name = A.prod_name)AND sales_date between"10/06/2014" and "10/06/2014" ),0) As Sold,
ifnull((Select SUM(po_qty) from tbl_PullOver Where po_prodID = (Select prod_id from tbl_prod where prod_name = A.prod_name) AND po_date between "10/06/2014" and "10/06/2014" ),0) As PullOut,
ifnull((Select SUM(itp_needQty) from tbl_itmonpur Where itp_prodID = (Select prod_id from tbl_prod where prod_name = A.prod_name)and itp_statusDelv = 'DELIVERED' and itp_date Between "10/06/2014" and "10/06/2014") - ((Select SUM(sales_qty) from tbl_sales Where sales_prodID = (Select prod_id from tbl_prod where prod_name = A.prod_name)AND sales_date between "10/06/2014" and "10/06/2014" ) + (Select SUM(po_qty) from tbl_PullOver Where po_prodID = (Select prod_id from tbl_prod where prod_name = A.prod_name) AND po_date between "10/06/2014" and "10/06/2014")), 0) As Stock,
S.supp_name As Supplier
From tbl_prod As A
Inner Join tbl_supp As S
On A.prod_suppID = S.supp_id
Group By Product;
我只是一名学生,请对我很轻松。谢谢!
答案 0 :(得分:0)
在MySQL中,您可以使用coalesce()
函数来处理这种情况:
- 的
coalesce(value, ...)
强>返回列表中的第一个非
NULL
值,如果没有非NULL
值,则返回NULL
。
示例:的
select coalesce(1, 2, 3); -- Will return 1
select coalesce(null, 2, 3); -- Will return 2
select coalesce(1, null, 3); -- Will return 1
select coalesce(null, null, null); -- Will return null