私はこれがあなたが望むことをするだろうと思います:
select sum(votes) as total, sum(demo*(1-rep)) as demoonly,
sum(rep*(1-demo)) as reponly, sum(demo*rep) as demorep
from (select address, cont(*) as votes,
max(case when voted = 'DEMO' then 1 else 0 end) as demo,
max(case when voted = 'REP' then 1 else 0 end) as rep
from t
group by address
) t
複数の人がいる世帯(住所)が必要だとすると、次のようになります。
select sum(votes) as total, sum(demo*(1-rep)) as demoonly,
sum(rep*(1-demo)) as reponly, sum(demo*rep) as demorep
from (select address, count(*) as votes,
max(case when voted = 'DEMO' then 1 else 0 end) as demo,
max(case when voted = 'REP' then 1 else 0 end) as rep
from test4
group by address
having count(distinct name) > 1
) t
ここでは、データに世帯フィールドがないため、「住所」は世帯のプロキシであると想定します。