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
Comments