You did not specify which RDBMS you are using, but this will work in all of them:
select id, name, max(case when period = 'monthly' then data1 end) as MonthlyData1, max(case when period = 'monthly' then data2 end) as MonthlyData2, max(case when period = 'quaterly' then data1 end) as quarterlyData1, max(case when period = 'quaterly' then data2 end) as quarterlyData2, max(case when period = 'halfYearly' then data1 end) as halfYearlyData1, max(case when period = 'halfYearly' then data2 end) as halfYearlyData2, max(case when period = 'annually' then data1 end) as annuallyData1, max(case when period = 'annually' then data2 end) as annuallyData2 from yourtable group by id, name
See SQL Fiddle with Demo
If you use an RDBMS with the PIVOT function, you can do the following, which uses both UNPIVOT and PIVOT to get the results. As Andriy M noted, UNPIVOT assumes that the data type for data1 and data2 are the same types, if not, then the conversion should take place for UNPIVOT data:
Oracle 11g:
select * from ( select id, name, value, period||data new_col from yourtable unpivot ( value for data in (data1, data2) ) u ) x pivot ( max(value) for new_col in ('monthlyDATA1', 'monthlyDATA2', 'quaterlyDATA1', 'quaterlyDATA2', 'halfYearlyDATA1', 'halfYearlyDATA2', 'annuallyDATA1', 'annuallyDATA2') ) p
See SQL Fiddle with Demo
SQL Server:
select * from ( select id, name, value, period+data new_col from yourtable unpivot ( value for data in (data1, data2) ) u ) x pivot ( max(value) for new_col in ('monthlyDATA1', 'monthlyDATA2', 'quaterlyDATA1', 'quaterlyDATA2', 'halfYearlyDATA1', 'halfYearlyDATA2', 'annuallyDATA1', 'annuallyDATA2') ) p