esta es mi query
Código SQL:
Ver original
SELECT COUNT(ti.id)AS total_id, datepart(MONTH,ti.create_time) AS mes, SUM(CASE WHEN DateDiff(MINUTE, ti.create_time, his.nlasttime) BETWEEN 0 AND 240 THEN 1 ELSE 0 END) AS Hasta4HH, SUM(CASE WHEN DateDiff(MINUTE, ti.create_time, his.nlasttime) BETWEEN 241 AND 480 THEN 1 ELSE 0 END) AS Hasta8HH, SUM(CASE WHEN DateDiff(MINUTE, ti.create_time, his.nlasttime) BETWEEN 481 AND 1440 THEN 1 ELSE 0 END) AS Hasta24HH, SUM(CASE WHEN DateDiff(MINUTE, ti.create_time, his.nlasttime) BETWEEN 1441 AND 4320 THEN 1 ELSE 0 END) AS Hasta72HH, SUM(CASE WHEN DateDiff(MINUTE, ti.create_time, his.nlasttime) BETWEEN 4321 AND 10080 THEN 1 ELSE 0 END) AS Hasta168HH, SUM(CASE WHEN DateDiff(MINUTE, ti.create_time, his.nlasttime) > 10080 THEN 1 ELSE 0 END) AS Mayores168HH FROM Otrs.dbo.ticket_history h INNER JOIN Otrs.dbo.ticket ti ON h.ticket_id = ti.id INNER JOIN Otrs.dbo.ticket_state s ON ti.ticket_state_id = s.id LEFT JOIN otrs.dbo.vwTicketHistoryClose his ON ti.id = his.ticket_id WHERE datepart(MONTH,ti.create_time)>= datepart(MONTH,DATEADD(MONTH,-1,getdate())) AND datepart(YEAR,ti.create_time)>= datepart(YEAR,DATEADD(MONTH,-1,getdate())) GROUP BY datepart(MONTH,ti.create_time)
mi problema es que me muestra un mes completo ejemplo hoy estamos a 7 de agosto y retrocede hasta el 7 de julio necesito que solo me muestre lo que va de agosto, alguien me podria ayudar con eso?
de antemano gracias!!
saludos