Re: [SQL ] oracle 同一欄位重複只列出一筆

看板Database作者 (如夢似幻)時間15年前 (2011/01/27 12:13), 編輯推噓2(202)
留言4則, 2人參與, 最新討論串4/4 (看更多)
※ 引述《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
ㄏㄏ!!TRM我有看,我也忘記打組織ID,可再請問一件事嗎?
01/29 01:24, 1F

01/29 01:29, , 2F
請問怎麼用connect by跟start with來寫這個問題
01/29 01:29, 2F

01/29 14:23, , 4F
google一下就很多範例,自行參考試試就可以了,只是sql不難
01/29 14:23, 4F
文章代碼(AID): #1DGF3mv6 (Database)
討論串 (同標題文章)
文章代碼(AID): #1DGF3mv6 (Database)