count multiple occurences of attribute values for each row in sql
select
  m1.id, 
  m1.attribute, 
  (select count(*) from mytable m2 where m2.attribute = m1.attribute) 
from
  mytable m1
;


Another version:

select
  m1.id,
  m1.attribute,
  m2.c
from
  mytable m1
  join (SELECT attribute, COUNT(attribute) as c FROM mytable GROUP BY attribute) m2
  on (m1.attribute = m2.attribute)
;


A better version for databases with analytic/window functions:

select
  m1.id,
  m1.attribute,
  count(*) over (partition by m1.attribute)
from
  mytable m1
;