Miguel. Try this:
select attribute, count(1) as count1
from mytable
where id2 in (
select distinct t.id2
from mytable t
join mytable t1 on (t1.id2 = t.id2 and t1.attribute = 'red')
where t.attribute = 'blue')
and attribute not in ('blue', 'red')
group by attribute
order by count1 desc;
Of course you will need some indexes. These could be enough:
1 > id2, attribute
2 > attribute, id2