更新:它现在可以正确提取每件商品最近交付的供应商名称。我现在遇到的问题是它没有提取以前没有交付的记录(空白 dlvry_dt)。有谁知道如何解决这一问题?
到目前为止,非常感谢您的帮助!
;WITH Items As(
Select
a.bin, a.item, d.item_description As 'Vintage', a.min_reorder,
c.minor_item_class, c.minor_class_description, a.qty_available,
a.reorder_threshold As 'Par', a.avg_unit_cost,
a.qty_available*a.avg_unit_cost As 'Valuation', e.dlvry_dt, g.supplier,
g.supplier_name,
RowNum = ROW_NUMBER() OVER(PARTITION BY a.item ORDER BY dlvry_dt DESC)
from argus.STORE_INVENTORY a, argus.MAJOR_ITEM_CLASS b,
argus.MINOR_ITEM_CLASS c, argus.ITEM_MASTER d, argus.DELIVERY e
inner join argus.delivery_line_item f
on e.delivery = f.delivery
and e.purchase_order = f.purchase_order
and e.customer = f.customer
and e.store = f.store
and e.supplier = f.supplier
full outer join argus.supplier g
on e.supplier = g.supplier
where a.customer = 10005
and a.store = 1
and d.item = a.item
and b.major_item_class = c.major_item_class
and d.minor_item_class = c.minor_item_class
and (b.major_item_class = 15 or b.major_item_class = 17 or b.major_item_class = 14)
and (c.minor_item_class = 830 or c.minor_item_class = 175 or c.minor_item_class = 880 or c.minor_item_class = 661 or c.minor_item_class = 651 or c.minor_item_class = 785 or c.minor_item_class = 716 or c.minor_item_class = 810 or c.minor_item_class = 850 or c.minor_item_class = 885 or c.minor_item_class = 998 or c.minor_item_class = 840 or c.minor_item_class = 855 or c.minor_item_class = 280)
and f.line_item_status <> 'D'
and e.customer = 10005
and e.store = 1
and f.item = a.item
--and (c.minor_item_class = 176 or c.minor_item_class = 651 or c.minor_item_class = 661 or c.minor_item_class = 716 or c.minor_item_class = 810 or c.minor_item_class = 830 or c.minor_item_class = 840 or c.minor_item_class = 850 or c.minor_item_class = 855 or c.minor_item_class = 885 or c.minor_item_class = 998)
Group By c.minor_class_description, a.bin, a.item, d.item_description, a.min_reorder, a.qty_available, a.reorder_threshold, a.avg_unit_cost, c.minor_item_class, e.dlvry_dt, g.supplier, g.supplier_name
)
Select bin, item, Vintage, min_reorder, minor_item_class, minor_class_description, qty_available, Par, avg_unit_cost, Valuation, dlvry_dt, supplier, supplier_name
From Items
Where RowNum =1
Order By minor_class_description