SQL query with start date and end date

0

I need to read some values in a table, I have to bring the values from 02/23/2016 until 02/23/2018, I tried to do it in SQL but it did not work so well, code below:

SELECT u.nome, un.descricao, (SELECT COALESCE(COUNT(DISTINCT(mc.id_marcacao_consulta)),0) 
                             FROM marcacao_consulta AS mc 
                             WHERE mc.id_usuario = u.id_usuario 
                               AND mc.id_status = 0
                               AND mc.data_cadastro BETWEEN "2014-03-08" AND "2018-03-08") AS total_marcacao, (SELECT COALESCE(COUNT(DISTINCT(mc.id_marcacao_consulta)),0) 
                             FROM marcacao_consulta AS mc 
                             WHERE mc.id_usuario = u.id_usuario 
                               AND mc.id_status <> 0
                               AND mc.ultima_atualizacao BETWEEN "2014-03-08" AND "2018-03-08") AS total_atendimento 
FROM usuario AS u 
    INNER JOIN usuario_nivel AS un ON u.id_usuario_nivel = un.id_usuario_nivel
WHERE u.ativo = 1 
HAVING total_marcacao <> 0 
   AND total_atendimento <> 0 
ORDER BY u.nome
    
asked by anonymous 09.03.2018 / 23:59

0 answers