select 'A' as E,max(case when E='AA' then a end) as AA,max(case when E='BB' then a end) as BB from tablename
union all
select 'B' as E,max(case when E='AA' then b end) as AA,max(case when E='BB' then b end) as BB from tablename
union all
select 'C' as E,max(case when E='AA' then c end) as AA,max(case when E='BB' then c end) as BB from tablename
union all
select 'D' as E,max(case when E='AA' then d end) as AA,max(case when E='BB' then d end) as BB from tablename