2016-10-03 74 views
0

我有以下表格:SQL用於連接不同的表

enter image description here

enter image description here

我想寫一個選擇Statment,顯示以下結果

enter image description here

我試圖加入/聯盟/聯盟所有的兩個表,但我沒有得到desird輸出。任何人都可以幫助我嗎?

+4

第二張桌子與您的問題有什麼關係?你需要某種支點,沒有聯合,也沒有聯盟。解決方案取決於您的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