This query will return number of tickets opened by month for the last rotating 12 months(NOT calendar year) grouped by Priority level.
SELECT
COUNT(HD_TICKET.ID) AS NUMBER_OPENED,
date_format(HD_TICKET.CREATED, '%M') AS MONTH_OPENED, HD_PRIORITY.NAME as PRIORITY_LEVEL
FROM
HD_TICKET
JOIN
HD_CATEGORY ON (HD_CATEGORY.ID = HD_TICKET.HD_CATEGORY_ID)
JOIN
HD_STATUS ON (HD_STATUS.ID = HD_TICKET.HD_STATUS_ID)
JOIN
HD_PRIORITY ON (HD_PRIORITY.ID = HD_TICKET.HD_PRIORITY_ID)
WHERE
((TIMESTAMP(HD_TICKET.CREATED) <= NOW()
AND TIMESTAMP(HD_TICKET.CREATED) >= DATE_SUB(NOW(), INTERVAL 12 MONTH)))
GROUP BY MONTH_OPENED, PRIORITY_LEVEL
ORDER BY HD_TICKET.CREATED, PRIORITY_LEVEL
Results look like this
Comments