Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Construindo consulta mysql para contar dados específicos na mesma tabela/linha


As COUNTs devem ser feitas em subconsultas separadas. Isso deve funcionar.

EDIT:Corrigido alguns erros estúpidos e incluiu um violino com a resposta.
SELECT DISTINCT E.created,F.flash,C.client
FROM events E
LEFT JOIN (
    SELECT created,COUNT(DISTINCT user_id) as flash
    FROM events
    WHERE event_type LIKE 'Flash C log'
    GROUP BY created
) F
ON F.created = E.created
LEFT JOIN (
    SELECT Created,COUNT(DISTINCT user_id) as client
    FROM events
    WHERE event_type LIKE 'Client C log'
    GROUP BY created
) C
ON C.created = E.created
WHERE E.created BETWEEN '2016-09-25' AND '2016-09-27'

Mexa nos resultados