mysql - Computed Value cant be seen maybe because of null -
my code here know status of inventory on range of date , i'm having problem when comes stock returns no value.
i have no values in pullover still should compute stock = delivered - (sold + pullover) here code.
select a.prod_name product, a.prod_totalprice price, a.prod_category category, a.prod_expdate expiration, ifnull((select sum(itp_needqty) tbl_itmonpur itp_prodid = (select prod_id tbl_prod prod_name = a.prod_name)and itp_statusdelv = 'delivered' , itp_date between "10/06/2014" , "10/06/2014"),0) delivered, ifnull((select sum(sales_qty) tbl_sales sales_prodid = (select prod_id tbl_prod prod_name = a.prod_name)and sales_date between"10/06/2014" , "10/06/2014" ),0) sold, ifnull((select sum(po_qty) tbl_pullover po_prodid = (select prod_id tbl_prod prod_name = a.prod_name) , po_date between "10/06/2014" , "10/06/2014" ),0) pullout, ifnull((select sum(itp_needqty) tbl_itmonpur itp_prodid = (select prod_id tbl_prod prod_name = a.prod_name)and itp_statusdelv = 'delivered' , itp_date between "10/06/2014" , "10/06/2014") - ((select sum(sales_qty) tbl_sales sales_prodid = (select prod_id tbl_prod prod_name = a.prod_name)and sales_date between "10/06/2014" , "10/06/2014" ) + (select sum(po_qty) tbl_pullover po_prodid = (select prod_id tbl_prod prod_name = a.prod_name) , po_date between "10/06/2014" , "10/06/2014")), 0) stock, s.supp_name supplier tbl_prod inner bring together tbl_supp s on a.prod_suppid = s.supp_id grouping product;
i'm pupil please easy on me. give thanks you!
in mysql can utilize coalesce()
function deal kind of situations:
coalesce(value, ...)
returns first non-null
value in list, or null
if there no non-null
values.
example:
class="lang-sql prettyprint-override">select coalesce(1, 2, 3); -- homecoming 1 select coalesce(null, 2, 3); -- homecoming 2 select coalesce(1, null, 3); -- homecoming 1 select coalesce(null, null, null); -- homecoming null
mysql vb.net
No comments:
Post a Comment