08-09-2017 11:57 AM
Select Top 1000000 TicketClosures.Year,
TicketClosures.Month,
Count(TicketClosures.ticketid) As TicketClosed
From (Select Distinct Top 1000000 htblhistory.ticketid,
DatePart(yyyy, htblhistory.date) As Year,
DatePart(mm, htblhistory.date) As Month
From htblhistory
Inner Join htblhistorytypes On htblhistorytypes.typeid = htblhistory.typeid
Inner Join htblticketstates On htblticketstates.ticketstateid =
htblhistory.ticketstateid
Where htblhistorytypes.name In ('status changed',
'Note added and state changed', 'Internal note added and state changed') And
htblticketstates.statename = 'Closed') TicketClosures
Inner Join htblticket On htblticket.ticketid = TicketClosures.ticketid
Where htblticket.spam <> 'True'
Group By TicketClosures.Year,
TicketClosures.Month
Order By TicketClosures.Year Desc,
TicketClosures.Month Desc
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now