Here is the original table :
id | type |
---|---|
1 | A |
1 | A |
1 | B |
2 | A |
Note that the content of type
is VARCHAR
and therefore can be anything.
I want to get an output like that :
id | A | B |
---|---|---|
1 | 2 | 1 |
2 | 1 | NULL |
How can I achieve that using mySQL ?
EDIT, here is what i tried so far :
SELECT u.id, i.type, count(*) as total
FROM intervention i,
intervention_user iu,
user u
WHERE i.id = iu.user_id
AND iu.user_id = u.id
GROUP BY i.type, u.id;