A simple report to control how many hours the people was working on tickets per cathegory in the last month. The most interesting thing is the instruction to take the tickets from the last month (we are always gonna make reports at the beggining of one month to control the last one) and the sum of working hours.

select
HD_CATEGORY.NAME as 'Categoria',

SUM(format(time_to_sec(timediff(HD_WORK.STOP,HD_WORK.START))/ 3600.0 + HD_WORK.ADJUSTMENT_HOURS,2)) AS 'Horas trabalhadas'


from HD_TICKET
     INNER JOIN HD_CATEGORY ON (HD_TICKET.HD_CATEGORY_ID = HD_CATEGORY.ID)
     INNER JOIN HD_WORK ON (HD_TICKET.ID = HD_WORK.HD_TICKET_ID)
INNER JOIN USER ON (HD_TICKET.SUBMITTER_ID=USER.ID),
     (SELECT ADDDATE(LAST_DAY(SUBDATE(LAST_DAY(SUBDATE(CURDATE(), INTERVAL 1 MONTH)),INTERVAL 1 MONTH)),1) PrimeiroDia,
           LAST_DAY(SUBDATE(CURDATE(), INTERVAL 1 MONTH)) UltimoDia from dual) T
           
WHERE
HD_TICKET.TIME_CLOSED between T.PrimeiroDia and T.UltimoDia

     
GROUP by
HD_CATEGORY.NAME