Time Intervals with Mysql

0

Hello friends I have a problem that I have been struggling with in the last few hours, it turns out that I have to graph the conversations that have not been answered, and these are the catalog from mysql, in a way:

one day, 3 days, 1 week, and one month, I give the example that I have 417 one-month conversations that have not been answered now I will show the sql sentences I use to get the intervals;

  • This is the first sql that brings the inboxes that are 1 day all great, this returns me as a quantity 30 conversations that have not been answered on the day
  • SELECT count(conver.ID_CONVERSACION) as inbox_un_dia  from mensaje as msj 
    INNER JOIN conversacion as conver on msj.conversacion_id_conversacion =  conver.ID_CONVERSACION where msj.created_time = conver.UPDATED_TIME 
    and msj.id_from <> $id_pagina and conver.pagina_ID_PAGINA = $id_pagina and msj.created_time between DATE_SUB(NOW(),INTERVAL '1' DAY) and NOW() ORDER BY conver.ID_CONVERSACION
    
  • this query brings the messages for 3 days and results in 48.
  • SELECT count(conver.ID_CONVERSACION) as inbox_tres_dias  from mensaje 
                        as msj INNER JOIN conversacion as conver 
                        on msj.conversacion_id_conversacion =  conver.ID_CONVERSACION where msj.created_time =  conver.UPDATED_TIME 
                        and msj.id_from <> $id_pagina and conver.pagina_ID_PAGINA = $id_pagina and msj.created_time between
                           DATE_SUB(NOW(),INTERVAL '3' DAY) and NOW() ORDER BY conver.ID_CONVERSACION
    
  • In this case it is the week and it results in 88 using a similar query
  • SELECT count(conver.ID_CONVERSACION) as inbox_una_semana  from mensaje 
                        as msj INNER JOIN conversacion as conver 
                        on msj.conversacion_id_conversacion =  conver.ID_CONVERSACION where msj.created_time =  conver.UPDATED_TIME 
                        and msj.id_from <> $id_pagina and conver.pagina_ID_PAGINA = $id_pagina and msj.created_time between
                             DATE_SUB(NOW(),INTERVAL '1' WEEK) and NOW() ORDER BY conver.ID_CONVERSACION
    

    ok friends now my problem is this, when the conversations of a day are created, this is all great, but when I have for example 3 days it shows me 48 which in reality only belong 18 messages because it takes me the 1st day, and what I need is how to send the parameter to the between, in advance I would greatly appreciate it, since I am new to this: $

        
    asked by Miguel Calles 08.08.2018 в 22:58
    source

    0 answers