看板 Database 關於我們 聯絡資訊
※ 引述《jimbosanho (chacha)》之銘言: 恕刪 : 終於解出來,放上來讓大家看看吧! : select segment1, : description : from( : select msib.segment1, : msib.description, : msib.inventory_item_id : from bom_bill_of_materials bbom, : mtl_system_items_b msib : where bbom.assembly_item_id = msib.inventory_item_id : and exists ( select 1 : from bom_inventory_components bic : where bic.bill_sequence_id = bbom.bill_sequence_id) : union all : select ' ' ||msib.segment1, : msib.description, : msib.inventory_item_id : from bom_inventory_component bic, : mtl_system_items_b msib : where bic.component_item_id = msib.inventory_item_id : and exist (select 1 : from bom_bill_of_materials bbom : where bic.bill_sequence_id = bbom.bill_sequence_id) : ) : order by inventory_item_id,segment1 desc 恕刪.... 看的出來您這段SQL使用的table是Oracle BOM & INV的部份, 但是您串錯了,BOM_BILL_OF_MATERIALS與MTL_SYSTEM_ITEMS_B 之間的unique key 是 organizatin_id & inventory_item_id, 可能是貴公司的環境僅有一個organization,所以沒出現笛卡爾 乘積的問題,如果是多組織的情況下,您這段SQL就錯很大了.... 建議您在寫SQL的時候,先看看table之間的關連性(像這是Oracle 的STD table,就可以去metalink上找尋相關版本的各模組的TRM 文件,裡面會介紹table & colume & unique key & foreign key), 希望對您有所幫助..... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.117.142.73
jimbosanho:ㄏㄏ!!TRM我有看,我也忘記打組織ID,可再請問一件事嗎? 01/29 01:24
jimbosanho:請問怎麼用connect by跟start with來寫這個問題 01/29 01:29
fantasyj:google一下就很多範例,自行參考試試就可以了,只是sql不難 01/29 14:23