2015-09-28 20 views
0

對不起,如果這聽起來含糊不清...我已經爲此尋找答案,但是,我覺得很難解釋 - 因此很難搜索。Oracle SQL結合了2個選擇到一列

我有一個非常簡單的腳本......

select pr1.polypart_no match_from, pr1.part_no match_to 
from oes_polybox_replace pr1 
where pr1.plant = 'W' 
and pr1.part_no = 
     (select max(pr2.part_no) 
      from oes_polybox_replace pr2 
      where pr2.plant = 'W' 
      and pr2.polypart_no = 'YPOLYGREY') 

...,顯示在第1列,零件號和第2欄,可以代替部分號碼使用的通用部分在第1列

enter image description here

我的問題是,我需要在第2列中添加部分第1列,即

enter image description here

有沒有辦法將2 select添加到一列?

+0

通過添加你的意思是'Y450168'和'Y453485'變成'Y450168Y453485'?目前尚不清楚您的圖片 – SearchAndResQ

+1

@ SearchAndResQ ...抱歉,沒有不是Y450168Y453485。 Y453485需要成爲列1列表中的另一部分(唯一行)。 – SMORF

+0

如果您只想讓MATCH_TO中的所有內容都位於MATCH_FROM列中,那麼是的,您可以將「UNION」兩個查詢放在一起。你想要一個例子嗎? –

回答

1

這裏是一個例子工會

select pr1.polypart_no match_from 
from oes_polybox_replace pr1 
where pr1.plant = 'W' 
and pr1.part_no = 
     (select max(pr2.part_no) 
      from oes_polybox_replace pr2 
      where pr2.plant = 'W' 
      and pr2.polypart_no = 'YPOLYGREY') 
UNION 
select pr1.part_no match_from 
from oes_polybox_replace pr1 
where pr1.plant = 'W' 
and pr1.part_no = 
     (select max(pr2.part_no) 
      from oes_polybox_replace pr2 
      where pr2.plant = 'W' 
      and pr2.polypart_no = 'YPOLYGREY') 

UNION僅選擇不同的值,UNION ALL沒有。

如果您需要重新訂購,您可以將其進一步包裝。

SELECT match_from from (
select pr1.polypart_no match_from 
    from oes_polybox_replace pr1 
    where pr1.plant = 'W' 
    and pr1.part_no = 
      (select max(pr2.part_no) 
       from oes_polybox_replace pr2 
       where pr2.plant = 'W' 
       and pr2.polypart_no = 'YPOLYGREY') 
    UNION 
    select pr1.part_no match_from 
    from oes_polybox_replace pr1 
    where pr1.plant = 'W' 
    and pr1.part_no = 
      (select max(pr2.part_no) 
       from oes_polybox_replace pr2 
       where pr2.plant = 'W' 
       and pr2.polypart_no = 'YPOLYGREY')) tab 
order by match_from asc 
+0

完美無缺......感謝羅伯特 – SMORF