select a as A,max(case when b='a' then c end) as a,max(case when b='b' then c end) as b,max(case when b='c' then c end) as c,max(case when b='d' then c end) as d from a