I have a mytable structured as follows and I would like to count occurences of values for attribute in each row:
id | attribute -------------- 1 | spam 2 | egg 3 | spam With
SELECT id, attribute, COUNT(attribute) FROM mytable GROUP BY attribute I only get
id | attribute | count ---------------------- 1 | spam | 2 2 | egg | 1 But what I would like as a result is
id | attribute | count ---------------------- 1 | spam | 2 2 | egg | 1 3 | spam | 2 How to achieve this?