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

1234567
  1. SELECT t3.itemno,
  2. SUM(t1.qty-ifnull(t4.qty,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. left join plm_item t3 on t1.siteid = t3.siteid and t1.itemid = t3.itemid
  6. LEFT JOIN (select t1.sa_dispatch_itemsid,t1.siteid,sum(t1.qty) qty from st_stockbill_items t1 inner join st_stockbill t2 on t1.st_stockbillid=t2.st_stockbillid and t1.siteid=t2.siteid where t2.status='审核' group by t1.sa_dispatch_itemsid,t1.siteid) t4 on t4.sa_dispatch_itemsid=t1.sa_dispatch_itemsid and t1.siteid=t4.siteid
  7. WHERE t2.STATUS in ('审核','复核') and t1.siteid=$siteid$ and t3.itemno in $itemnos$ group by t3.itemno