2016-10-03 21 views
0

別のテーブルを結合するためのSQL:私は以下の表を持って

enter image description here

enter image description here

私は選択なステートメントを書きたい、次の結果を表示

enter image description here

I参加しようとする/ユニオン/ユニオンすべての2つのテーブルが、私は砂漠の出力を取得しないでください。誰もそれで私を助けることができますか?

+4

どのように2番目のテーブルがあなたの問題に関連していますか?あなたは何らかの種類のピボットを必要とし、結合や結合は必要ありません。このソリューションはOracleのバージョンに依存します.Oracleのバージョンは常に質問に含める必要があります。 – mathguy

+2

データをテキストとして貼り付けてください。テストに役立ち、画像がブロックされている人にも役立ちます。 – TheGameiswar

+0

私はピボットを使用しようとしましたが、私は新しいので、私は望みの出力を得ませんでした – Maryam

答えて

0
select 
'group_a' as groupname 
, max(case classname when 'C123' then group_a else null end) as c123 
, max(case classname when 'C456' then group_a else null end) as c456 
from table1 
union all 
select 
'group_b' as groupname 
, max(case classname when 'C123' then group_b else null end) as c123 
, max(case classname when 'C456' then group_b else null end) as c456 
from table1 
union all 
select 
'group_d' as groupname 
, max(case classname when 'C123' then group_d else null end) as c123 
, max(case classname when 'C456' then group_d else null end) as c456 
from table1 
union all 
select 
'group_e' as groupname 
, max(case classname when 'C123' then group_e else null end) as c123 
, max(case classname when 'C456' then group_e else null end) as c456 
from table1 
関連する問題