57,062
社区成员
发帖
与我相关
我的任务
分享
select i.fk_in_no,i.fk_vender_abbrev,i.fk_factory_abbrev,i.fk_part_no,i.fk_spec,i.fk_commodity,i.qty,
i.qty-
ifnull((select sum(o.qty)
from ve_report_outbound_detail o
where i.fk_in_no=o.fk_in_no
and i.fk_part_no=o.fk_vender_part_no
and i.fk_spec=o.fk_vender_spec
and i.fk_commodity=o.fk_vender_commodity
and i.fk_qty_unit_abbrev=o.fk_qty_unit_abbrev),0) as stock_qty,i.fk_qty_unit_abbrev,i.inbound_time
from ve_report_inbound_detail i
having stock_qty>0
SELECT i.fk_in_no,
i.fk_vender_abbrev,
i.fk_factory_abbrev,
i.fk_part_no,
i.fk_spec,
i.fk_commodity,
i.qty,
i.qty - o.out_qty AS stock_qty,
i.fk_qty_unit_abbrev,
i.inbound_time
FROM ve_report_inbound_detail i
LEFT JOIN
( SELECT fk_in_no,
fk_vender_part_no,
fk_vender_spec,
fk_vender_commodity,
fk_qty_unit_abbrev,
sum(qty) AS out_qty
FROM ve_report_outbound_detail
GROUP BY fk_in_no,
fk_vender_part_no,
fk_vender_spec,
fk_vender_commodity,
fk_qty_unit_abbrev) o
ON ( i.fk_in_no = o.fk_in_no
AND i.fk_part_no = o.fk_vender_part_no
AND i.fk_spec = o.fk_vender_spec
AND i.fk_commodity = o.fk_vender_commodity
AND i.fk_qty_unit_abbrev = o.fk_qty_unit_abbrev)
where i.qty>o.out_qty or o.out_qty is null
SELECT i.fk_in_no,
i.fk_vender_abbrev,
i.fk_factory_abbrev,
i.fk_part_no,
i.fk_spec,
i.fk_commodity,
i.qty,
i.qty - ifnull(o.out_qty, 0) AS stock_qty,
i.fk_qty_unit_abbrev,
i.inbound_time
FROM ve_report_inbound_detail i
LEFT JOIN
( SELECT fk_in_no,
fk_vender_part_no,
fk_vender_spec,
fk_vender_commodity,
fk_qty_unit_abbrev,
sum(qty) AS out_qty
FROM ve_report_outbound_detail
GROUP BY fk_in_no,
fk_vender_part_no,
fk_vender_spec,
fk_vender_commodity,
fk_qty_unit_abbrev) o
ON ( i.fk_in_no = o.fk_in_no
AND i.fk_part_no = o.fk_vender_part_no
AND i.fk_spec = o.fk_vender_spec
AND i.fk_commodity = o.fk_vender_commodity
AND i.fk_qty_unit_abbrev = o.fk_qty_unit_abbrev)
HAVING stock_qty > 0

select i.fk_in_no,i.fk_vender_abbrev,i.fk_factory_abbrev,i.fk_part_no,i.fk_spec,i.fk_commodity,i.qty,
i.qty-o.qty as stock_qty,
i.fk_qty_unit_abbrev,i.inbound_time
from ve_report_inbound_detail i inner join (
select fk_in_no,fk_vender_part_no,fk_vender_spec,fk_vender_commodity,fk_qty_unit_abbrev,sum(qty) as qty
from ve_report_outbound_detail
group by fk_in_no,fk_vender_part_no,fk_vender_spec,fk_vender_commodity,fk_qty_unit_abbrev
) o on i.fk_in_no=o.fk_in_no
and i.fk_part_no=o.fk_vender_part_no
and i.fk_spec=o.fk_vender_spec
and i.fk_commodity=o.fk_vender_commodity
and i.fk_qty_unit_abbrev=o.fk_qty_unit_abbrev
where i.qty>o.qty