商品发货数量汇总.sql 577 B

12345678
  1. SELECT t3.itemno,
  2. SUM(t1.qty-ifnull(t1.outwarehouseqty,0)) qty
  3. FROM sa_dispatch_items t1
  4. inner join sa_dispatch t2 on t1.siteid = t2.siteid and t1.sa_dispatchid = t2.sa_dispatchid
  5. inner join plm_item t3 on t1.siteid = t3.siteid and t1.itemid = t3.itemid
  6. left join sys_enterprise t5 on t2.sys_enterpriseid=t5.sys_enterpriseid and t2.siteid=t5.siteid
  7. left join sa_agents t6 on t6.sys_enterpriseid=t2.sys_enterpriseid and t2.siteid=t6.siteid
  8. WHERE t2.STATUS in ('审核','复核') and t1.siteid=$siteid$ and $where$ group by t3.itemno