2017-03-17 31 views
1

首先,我必須說,我在SQL查詢方面非常新,但在其他問題中我發現了很多幫助。但現在,我卡住了。Oracle SQL獨立查詢3而不是1行

我下面的語句:

select distinct part_no, 
    case when cf$_package_type_db='RETAIL' then gtin_no end as retail, 
    case when cf$_package_type_db='INNER' then gtin_no end as "inner", 
    case when cf$_package_type_db='OUTER' then gtin_no end as outer 
from part_gtin_cfv 
where part_no='182400B000305' 

這給了我下面的結果:

enter image description here

我想吃點什麼是結果只有一行

+0

這個查詢是否真的執行? (生成結果。) – jarlh

+0

對不起,對於截圖中的結果,我沒有用funktion來使用這個組。當我試圖獲得一行輸出時,它被添加。我會編輯我的原始文章 – Lucky

回答

0

如果每個Pat_no只有一個,請嘗試:

select part_no, 
    max(case when cf$_package_type_db='RETAIL' then gtin_no end) as retail, 
    max(case when cf$_package_type_db='INNER' then gtin_no end) as "inner", 
    max(case when cf$_package_type_db='OUTER' then gtin_no end) as outer 
from part_gtin_cfv 
where part_no='182400B000305' 
group by part_no 
+0

非常感謝!我編輯了我原來的帖子,並刪除了group_by函數,而不是在原始查詢中,它與「_」 – Lucky