example select:
select *
from (
select 1 cnt, 2 sm, '55' name, 12 month, 2011 year, '12 2011' mnth_txt from dual union all
select 1 cnt, 2 sm, '54' name, 11 month, 2011 year, '11 2011' mnth_txt from dual union all
select 1 cnt, 2 sm, '55' name, 11 month, 2011 year, '11 2011' mnth_txt from dual union all
select 1 cnt, 2 sm, '54' name, 12 month, 2011 year, '12 2011' mnth_txt from dual union all
select 1 cnt, 2 sm, '55' name, 12 month, 2011 year, '12 2011' mnth_txt from dual union all
select 1 cnt, 2 sm, '56' name, 12 month, 2010 year, '12 2010' mnth_txt from dual
) pivot (
sum(cnt) cnt, sum(sm) sm
for name in
( '55' as "Omsk"
, '54' as "Novosibirsk"
, '56' as "Orenburg"
)
)
output:
|month| year | mnth_txt |Omsk_cnt|Omsk_sm|Novosibirsk_cnt|Novosibirsk_sm|Orenburg_cnt| Orenburg_sm|
| 12 | 2010 |'12 2010' | (null) | (null)| (null) | (null) | 1 | 2 |
| 12 | 2011 |'12 2011' | 2 | 4 | 1 | 2 | (null) | (null) |
| 11 | 2011 |'11 2011' | 1 | 2 | 1 | 2 | (null) | (null) |
is it possible to sort the records in chronological order, with the excluding columns "month" and "year"? Without listing all the columns.
UPD
need:
| mnth_txt |Omsk_cnt|Omsk_sm|Novosibirsk_cnt|Novosibirsk_sm|Orenburg_cnt| Orenburg_sm|
|'12 2010' | (null) | (null)| (null) | (null) | 1 | 2 |
|'11 2011' | 1 | 2 | 1 | 2 | (null) | (null) |
|'12 2011' | 2 | 4 | 1 | 2 | (null) | (null) |
something like:
select mnth_txt, pivoted_columns.*