select c.product_item_name,a.*, b.quantity_in
from (select product_item_id, sum(product_quantity) as s
from pcs_shop_order_item where shop_order_id
in (select id from pcs_shop_order
where expect_approach_time <= #{expectApproachTime}
and s.order_status = 20)
group by product_item_id) as a
left join wms_product_main_stock b on a.product_item_id = b.product_item_id
left join pms_product_item c on a.product_item_id = c.id ;
<where>
and o.delete_flag = 0
</where>
order by create_time desc
//采购数量和库存缺货数量 SQL书写