Re: [SQL ] oracle 同一欄位重複只列出一筆
※ 引述《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
推
01/29 01:24, , 1F
01/29 01:24, 1F
推
01/29 01:29, , 2F
01/29 01:29, 2F
→
01/29 14:15, , 3F
01/29 14:15, 3F
→
01/29 14:23, , 4F
01/29 14:23, 4F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 4 之 4 篇):