我讀過一些問題,但目前尚不清楚對我來說,我不能用樞軸移調一個表甲骨文10
我有下表:
ID AREA CAR
1 A1 A
1 A2 B
1 A3 C
2 A1 D
2 A2 E
3 A2 F
3 A3 G
而且我想一些像
ID AREA1 CAR1 AREA2 CAR2 AREA3 CAR3
1 A1 A A2 B A3 C
2 A1 D A2 D null null
3 null null A2 F A3 G
區域的數量是固定的,只是A1,A2,A3。
我試着
SELECT id, area1,car1,area2,car2
FROM ( SELECT id,
case when AREA='A1' then AREA else NULL end area1,
case when AREA='A1' then CAR else NULL end car1,
case when AREA='A2' then AREA else NULL end area2,
case when AREA='A2' then CAR else NULL end car2,
case when AREA='A3' then AREA else NULL end area3,
case when AREA='A3' then CAR else NULL end car3
FROM TABLA
GROUP BY id);
,但我得到:
"not a GROUP BY expression"
我能做些什麼有一個正確的GROUP BY表達和正常轉我的表? 有沒有更好的解決方案呢?
在此先感謝
我讀過 http://stackoverflow.com/questions/1788011/transpose-select-results-with-oracle 但我不明白:( – OscarSan 2012-08-09 17:37:58