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?