create view view_jin_xiao_cun2 as SELECT a.jiezhuan_prod_code as prod_code,a.jiezhuan_prod_name as prod_name, IFNULL(b.jiezhuan_count,0) as qichu_count,IFNULL(b.jiezhuan_money,0) as qichu_money, IFNULL(c.入库数量,0) as ruku_count,IFNULL(c.入库金额,0) as ruku_money, IFNULL(d.出库数量,0) as chuku_count,IFNULL(d.出库金额,0) as chuku_money, IFNULL(b.jiezhuan_count,0)+IFNULL(c.入库数量,0)-IFNULL(d.出库数量,0) as kucun_count, round((IFNULL(b.jiezhuan_money,0)+IFNULL(c.入库金额,0)-IFNULL(d.出库金额,0))/(IFNULL(b.jiezhuan_count,0)+IFNULL(c.入库数量,0)-IFNULL(d.出库数量,0)),2) as kucun_price, IFNULL(b.jiezhuan_money,0)+IFNULL(c.入库金额,0)-IFNULL(d.出库金额,0) as kucun_money from (select jiezhuan_prod_code,jiezhuan_prod_name from yiyun_kucunjiezhuan UNION select prod_code,prod_name from yiyun_ruku union select prod_codechuku,prod_namechuku from yiyun_chuku ORDER BY jiezhuan_prod_code) as a left join (SELECT * from yiyun_kucunjiezhuan) as b on a.jiezhuan_prod_code=b.jiezhuan_prod_code left join (SELECT prod_code,sum(ruku_count) as 入库数量,sum(ruku_money) as 入库金额 from yiyun_ruku group by prod_code) as c on a.jiezhuan_prod_code = c.prod_code left join (select prod_codechuku,sum(chuku_count) as 出库数量,sum(chuku_money) as 出库金额 from yiyun_chuku GROUP BY prod_codechuku) as d on a.jiezhuan_prod_code = d.prod_codechuku GROUP BY a.jiezhuan_prod_code ORDER BY 出库金额 desc
标签:count,逆向,code,IFNULL,money,视图,mysql,jiezhuan,prod From: https://www.cnblogs.com/eyunkeji/p/17091966.html