2
Hello, I have a table of activities that lists activity data, including her status.
I would like to sum up the activities of a particular user and display in a graph, showing according to the status of the activity. (Type, always add +1 according to status).
For example:
The user Bruno has: 25 activities with expired status. 10 activities with pending status. 30 activities with completed status.
I’m trying to use the code below in Mysql:
SELECT
SUM(CASE WHEN STATUS = 'CONCLUIDO' THEN 1 ELSE 0) AS Concluido,
SUM(CASE WHEN STATUS = 'CONCLUIDO_VENCIDO' THEN 1 ELSE 0) AS Concluido_Vencido,
SUM(CASE WHEN STATUS = 'INICIADO' THEN 1 ELSE 0) AS Iniciado,
SUM(CASE WHEN STATUS = 'INICIADO_VENCIDO' THEN 1 ELSE 0) AS Iniciado_Vencido,
SUM(CASE WHEN STATUS = 'PENDENTE' THEN 1 ELSE 0) AS Pendente,
SUM(CASE WHEN STATUS = 'VENCIDO' THEN 1 ELSE 0) AS Vencido
FROM tbl_atividades WHERE responsavel = "BRUNO";
- The code is giving error.
Description of table tbl_activities:
** Follows the error presented **
Thank you!
Although you have not informed which error I believe that END is missing in each of the CASE. GROUP BY clause is not missing?
– anonimo
Ah, sorry. I’ll edit and show the error.
– Gato de Schrödinger
It would not be the case to use a Count with a group by status?
– Felipe Avelar