Pues si tienes en tu where -1 mes pues te va a mostrar todo lo del mes de julio mas agosto, si nada mas quieres lo de este mes podrias usar:
Código SQL:
Ver originalSELECT
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,getdate()) AND
datepart(YEAR,ti.create_time)>= datepart(YEAR,DATEADD(MONTH,-1,getdate()))
GROUP BY datepart(MONTH,ti.create_time)