I have a table with these data :
SELECT typeId, status FROM geo WHERE userId = 1 LIMIT 5;
+--------+--------+
| typeId | status |
+--------+--------+
| 2 | 2 |
| 2 | 5 |
| 8 | 2 |
| 3 | 3 |
| 2 | 5 |
+--------+--------+
And I'd like to count the number of different status per typeID. Here the expected result:
status 2 = active
status 3 = disabled
status 5 = archived
+--------+--------+----------+----------+
| typeId | active | disabled | archived |
+--------+--------+----------+----------+
| 2 | 1 | 0 | 2 |
| 8 | 1 | 0 | 0 |
| 3 | 0 | 1 | 0 |
+--------+--------+----------+----------+
0 can be is NULL, not a problem
I tried with a query like that : "SELECT typeId, CASE WHEN status = 2 THEN status END AS active, CASE WHEN status = 3 THEN status END AS disabled, CASE WHEN status = 5 THEN status END AS archived FROM geo WHERE userId = 1 group by typeId" but of course it's not the expected result.. I got the status, not the count and I don't know how to count them.
Thanks for your help!