Cari Blog Ini
29 Mei 2012
How to Use Pivot Table - 2
1. Sample Data
-----code:start
select * from sp_PerTahun_Jumlah_Kelompok_Umur_Results_Backup
order by 1,2
-----code:end
2. Use Pivot Table
-----code:start
select
Per_Tahun
,'15-19'=max(case when Range_Umur='15-19' then Umur end)
,'20-24'=max(case when Range_Umur='20-24' then Umur end)
,'25-29'=max(case when Range_Umur='25-29' then Umur end)
,'30-34'=max(case when Range_Umur='30-34' then Umur end)
,'35-39'=max(case when Range_Umur='35-39' then Umur end)
,'40-44'=max(case when Range_Umur='40-44' then Umur end)
,'45-49'=max(case when Range_Umur='45-49' then Umur end)
,'50-54'=max(case when Range_Umur='50-54' then Umur end)
,'55-59'=max(case when Range_Umur='55-59' then Umur end)
,'60-99'=max(case when Range_Umur='60-99' then Umur end)
from sp_PerTahun_Jumlah_Kelompok_Umur_Results_Backup as A
group by Per_Tahun
-----code:end