Since you use different criteria for "uniqueness" for d12 and d34, you need two selects, but you can combine them e.g. by using a UNION. I would do like this:
select d1, d2, sum(d12), null, null, null from mytable group by d1, d2
union all
select null, null, null, d3, d4, sum(d34) from mytable group by d3, d4