I am trying to transpose rows to columns without any luck . What I have now
| WEEK_NUMBER | VAL9 | VAL4 | VAL5 | VAL7 |
|---|---|---|---|---|
| 45 | 63.27% | 28.58% | 7.92% | 0.23% |
| 52 | 65.66% | 26.16% | 7.80% | 0.38% |
| 50 | 90.97% | 8.45% | 0.29% | 0.29% |
| 46 | 82.49% | 12.43% | 3.01% | 2.06% |
| 47 | 66.33% | 29.53% | 3.77% | 0.36% |
| 51 | 65.36% | 31.83% | 2.69% | 0.11% |
| 49 | 61.88% | 28.29% | 9.46% | 0.37% |
| 44 | 45.34% | 45.55% | 8.45% | 0.66% |
| 48 | 43.75% | 40.01% | 16.01% | 0.23% |
this is based on the following query
select
to_char(for_date,'ww') as week_number
,val9
,val4
,val5
,val7
from data_tab
where to_char(for_date,'yy') = '21'
I am trying to get following result
| 01 | 02 | .. | 51 | 52 | |
|---|---|---|---|---|---|
| VAL9 | 0 | 0 | .. | 65.36% | 65.66% |
| VAL4 | 0 | 0 | .. | 31.83% | 26.16% |
| VAL5 | 0 | 0 | .. | 2.69% | 7.80% |
| VAL7 | 0 | 0 | .. | 0.11% | 0.38% |
I have tried by doing next query but with no luck . If someone can just point me in the right direction I would appreciate.
select * from (
select
to_char(for_date,'ww') as week_number
,val9
,val4
,val5
,val7
from data_tab
where to_char(for_date,'yy') = '21')
pivot (
min(val9)--, min(val4), min(val5), min(val7)
for week_number in (01 ,02 ,03 ,04 ,05 ,06 ,07 ,08 ,09 ,10 ,11 ,12 ,13 ,14 ,15 ,16 ,17 ,18 ,19 ,20 ,21 ,22 ,23 ,24 ,25 ,26 ,27 ,28 ,29 ,30 ,31 ,32 ,33 ,34 ,35 ,36 ,37 ,38 ,39 ,40 ,41 ,42 ,43 ,44 ,45 ,46 ,47 ,48 ,49 ,50 ,51 ,52 ,53)
)