请帮忙优化这个SQL吧----在线等

[复制链接]
查看11 | 回复3 | 2005-10-30 17:05:33 | 显示全部楼层 |阅读模式
select
to_char(mmt.transaction_date,'MM-YYYY')
,decode(mmt.organization_id,93,'股份',99,'集团')
,msi.attribute1
,decode(mmt.transaction_type_id,18,'PO 接收',36,'向供应商退货')
,msi.inventory_item_id ITEM_ID
,msi.segment1 物料编码
,msi.description 物料说明
,inv.secondary_inventory_name 子库编码
,rsh.receipt_num 单据号
,decode(mmt.transaction_type_id,18,to_number(rt.attribute14),36,to_number(rt.attribute14))
,decode(mmt.transaction_type_id,18,mmt.transaction_quantity,36,-mmt.transaction_quantity)
,mmt.transaction_uom 单位
,to_char(mmt.transaction_date,'YYYY-MM-DD') 业务时间
,mmt.created_by created_by
from
rcv_transactions rt
,rcv_shipment_headers rsh
,mtl_material_transactions mmt
,mtl_system_items_b msi
,mtl_secondary_inventories inv
,mtl_transaction_types mtt
where mmt.rcv_transaction_id=rt.transaction_id
and rt.shipment_header_id=rsh.shipment_header_id
and msi.organization_id=94
and mmt.inventory_item_id=msi.inventory_item_id
and mmt.transaction_type_id=mtt.transaction_type_id
and rt.po_line_location_id is not null
and mmt.rcv_transaction_id is not null
--and rt.transaction_type in ('DELIVER','RETURN TO VENDOR')
and mmt.subinventory_code=inv.secondary_inventory_name
and mtt.transaction_type_id in (18,36)
and (msi.attribute1=1 or msi.attribute1=3)
--and mmt.created_by=-1
and mmt.transaction_date between sysdate-60 and sysdate

怎么进一步优化,请高手帮忙
回复

使用道具 举报

千问 | 2005-10-30 17:05:33 | 显示全部楼层
基本上,你的 SQL 有些問題,
where msi.organization_id=94
但 未見
msi.organization_id=mmt.organization_id
為何?
而若你有限這個條件,

decode(mmt.organization_id,93,'股份',99,'集团')
這個輸出又顯得奇怪
應該是把你的 SQL 寫對了,再來談優化...
回复

使用道具 举报

千问 | 2005-10-30 17:05:33 | 显示全部楼层
sql没有问题,其料号存在多组织,塞选一个比较全的即可。
建议使用toad tuning,会给你比较好的建议,一般原则,有索引,primary放在前面
回复

使用道具 举报

千问 | 2005-10-30 17:05:33 | 显示全部楼层
比较全的应该是在主组织里呀
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行