MySQL GROUP BY - Error in PHP

0

I have a query in MySQL that, in the command line and in MySQL Workbench, is bringing the correct values, but when executed in PHP, the GROUP BY function is grouping more than it should!

Here is the query:

SELECT
    DATE_FORMAT(ctg.data_de_criacao, '%d/%m/%Y') AS DataMes,
    ctg.assunto,
    COUNT(*) AS InTS
FROM
    registro_atend AS ctg FORCE INDEX (idx_datacriacao)
    INNER JOIN
    registro_atend_ocorrencias AS cto ON ctg.idx_primary = cto.idx_primary
WHERE
    ctg.protocolo_da_ocorrencia > 0
    AND
                ctg.data_de_criacao BETWEEN '2016-01-01 00:00:00' AND '2016-12-31 23:59:59'
    AND
        ctg.campanha REGEXP 'camp1|camp2'
    AND
        ctg.assunto REGEXP 'card|credit|delivery'
    AND
        ctg.detalhe_do_assunto REGEXP 'analisys|not_delivered|receive_error|password_mail_corrupt'
    AND
        cto.setor_responsavel REGEXP 'credit1|delivery1'
GROUP BY DataMes, ctg.assunto
ORDER BY ctg.assunto, DataMes;

In the Workbench, the query brings me 77 lines, normally. In PHP, only 9 are returned. (I used var_dump after the query)

I made some tests, and the problem is in group by , but I need the result to exit in that format.

I have over 100 queries in the same way, but only this one is giving trouble.

How to solve?

    
asked by anonymous 25.02.2016 / 19:17

1 answer

1

I changed COUNT(*) by SUM(CASE WHEN ctg.assunto = 'xxxxx' THEN 1 END) and replaced group by group by DataMes , so I have the ctg.assunto counts in vertical columns, not in clustered rows.

It will serve! But I still do not understand why the previous one did not work, and all the others are working normally and the only thing that changes is the name of the columns ...

You will understand!

    
25.02.2016 / 20:15