SQL query with start date and end date

Asked

Viewed 380 times

0

Guys, I need to consult some values in a table, I have to bring the values of the day 23/02/2016 until the day 23/02/2018, I tried to do in SQL but it did not work so right, 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
  • Which error appears?

  • is the following, I forgot to mention, but I also need a specific time, that is from 7am to 13h, but when I put the time, it returns the same value of that code (this doubt code is without the time), so I suspect that there is something wrong there

  • The data in this column are in what format?

  • timestamp Edson

  • timestamp Edson

  • Try to convert the values to Unix and perform the operation.

  • which database is using ?

  • Date functions change according to the DBMS, inform the same.

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.