原始查询返回259行。修改后,查询返回271行。这十二行是重复的。我怎么能避免这个?谢谢你的帮助!!
查询(修改粗体):
select "Item", "Expires", "Lot #", "Subinv", "Locator", "Qty", "UOM", "Lead Time"
,(select count(*) from MTL_KANBAN_CARDS_V kb where exp.inventory_item_id = kb.inventory_item_id and kb.card_status_name <> 'Hold') "Kanban Cards (Not On Hold)"
FROM (
SELECT msi.inventory_item_id
,msi.segment1 "Item"
,mln.expiration_date "Expires"
,mln.lot_number "Lot #"
,moqd.subinventory_code "Subinv"
,mil.segment1 "Locator"
,sum(moqd.primary_transaction_quantity) "Qty"
,msi.primary_uom_code "UOM"
**,muc.conversion_rate "UOM Conversion Rate"**
,msi.FULL_LEAD_TIME "Lead Time"
FROM mtl_system_items_b msi
,mtl_onhand_quantities_detail moqd
,mtl_lot_numbers mln
,mtl_item_locations mil
**,mtl_uom_conversions muc**
WHERE msi.organization_id = 101
AND moqd.inventory_item_id = msi.inventory_item_id
AND moqd.organization_id = msi.organization_id
**AND muc.inventory_item_id (+) = msi.inventory_item_id**
AND mln.inventory_item_id = msi.inventory_item_id
AND mln.organization_id = msi.organization_id
AND mln.lot_number = moqd.lot_number
AND mln.expiration_date <= SYSDATE+365
AND mil.organization_id(+) = moqd.organization_id
AND mil.inventory_location_id(+) = moqd.locator_id
GROUP BY msi.inventory_item_id
,msi.segment1
,mln.expiration_date
,mln.lot_number
,moqd.subinventory_code
,mil.segment1
,msi.primary_uom_code
**,muc.conversion_rate**
,msi.FULL_LEAD_TIME
ORDER BY msi.segment1
,mln.expiration_date
,mln.lot_number) exp
答案 0 :(得分:1)
我试着将其表述为答案:
对于13个项目,特定conversion_rate
的值不止一个inventory_item_id
,这就是为什么在您按mtl_uom_conversions
扩展查询后这些额外的行会亮起来。
如果你不想全部拥有它们,你可以......
(1)删除这些副本;我认为这没关系,因为对我来说,似乎数据库中的数据在这种情况下是不一致/冗余的
(2)从group by子句中删除muc.conversion_rate
并在(inner)select子句中添加min(muc.conversion_rate)
;你也可以使用MAX,或者其他什么,但是如果你有更多的值,但只想要一个,你必须决定哪一个: - )