Report of Total Tickets per Month for the Year
My boss wants a report with the total tickets per month for the year and for the life of me I have no idea how to manage that. Has anyone had to do this before? No need for categories or anything. Simply raw numbers.
Answers (4)
Here's the main one I use, with owners listed. The second one is a tweak that does not include the owners column. If you need help tweaking it any further, just let me know.
Hope that helps!
John
________________________________
*Title*
Ticket Count by Owner (Current Year)
*Report Category*
Helpdesk (Custom)
*Description*
Lists ticket count by owner and status by month for current year.
*SQL Select Statement*
SELECT OPEN.OWNER, OPEN.MONTH, OPEN.YEAR, Coalesce(OPEN.OPEN, 0) AS OPENED, Coalesce(CLOSED.CLOSED, 0) AS CLOSED
FROM (SELECT Coalesce(U.USER_NAME, 'NO OWNER ASSIGNED') AS OWNER, date_format(T.CREATED, '%M') AS MONTH, YEAR (T.CREATED) AS YEAR, COUNT(*) AS OPEN
FROM HD_TICKET T
LEFT JOIN USER U ON T.OWNER_ID = U.ID
GROUP BY OWNER_ID, MONTH, YEAR
ORDER BY YEAR, MONTH) OPEN
LEFT JOIN (SELECT Coalesce(U.USER_NAME, 'NO OWNER ASSIGNED') AS OWNER, date_format(T.TIME_CLOSED, '%M') AS MONTH, YEAR (T.TIME_CLOSED) AS YEAR, COUNT(*) AS CLOSED
FROM HD_TICKET T
JOIN HD_STATUS S ON HD_STATUS_ID=S.ID and S.STATE ='Closed'
LEFT JOIN USER U ON T.OWNER_ID = U.ID
GROUP BY OWNER_ID, MONTH, YEAR
ORDER BY YEAR, MONTH) CLOSED
ON (OPEN.MONTH = CLOSED.MONTH AND OPEN.YEAR = CLOSED.YEAR AND OPEN.OWNER = CLOSED.OWNER )
WHERE OPEN.YEAR = date_format(curdate(), '%Y')
ORDER BY YEAR desc, str_to_date(OPEN.MONTH,'%M') desc, OWNER
*Break on Columns*
MONTH
________________________________
*Title*
Ticket Count (Current Year)
*Report Category*
Helpdesk (Custom)
*Description*
Lists ticket count by status by month for current year.
*SQL Select Statement*
SELECT OPEN.MONTH, OPEN.YEAR, Coalesce(OPEN.OPEN, 0) AS OPENED, Coalesce(CLOSED.CLOSED, 0) AS CLOSED
FROM (SELECT date_format(T.CREATED, '%M') AS MONTH, YEAR (T.CREATED) AS YEAR, COUNT(*) AS OPEN
FROM HD_TICKET T
GROUP BY MONTH, YEAR
ORDER BY YEAR, MONTH) OPEN
LEFT JOIN (SELECT date_format(T.TIME_CLOSED, '%M') AS MONTH, YEAR (T.TIME_CLOSED) AS YEAR, COUNT(*) AS CLOSED
FROM HD_TICKET T
JOIN HD_STATUS S ON HD_STATUS_ID=S.ID and S.STATE ='Closed'
GROUP BY MONTH, YEAR
ORDER BY YEAR, MONTH) CLOSED
ON (OPEN.MONTH = CLOSED.MONTH AND OPEN.YEAR = CLOSED.YEAR)
WHERE OPEN.YEAR = date_format(curdate(), '%Y')
ORDER BY YEAR desc, str_to_date(OPEN.MONTH,'%M') desc
Comments:
-
Is there a way to take the ability to sort by month you have above, and add it to my own report I made with the wizard, replacing the interval section? - edwimb 11 years ago
-
Yes, it should be possible, but some things (like the date formats) may need to be tweaked to get things working.
I'm providing the baseline and simplified versions of the reports below, to hopefully make transplanting what you want a bit easier. But if this is still not clear, try running the queries below and compare the T.CREATED value's format against what you get for MONTH and YEAR values. Then research the following date functions to get a better understanding of what they are doing and how they work:
date_format()
str_to_date()
year()
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html
____________________________________________________
baseline version without any date functions
select T.CREATED,
count(*) as OPEN
from HD_TICKET T
order by T.CREATED
____________________________________________________
Simplified version - only tickets with an Open status
select date_format(T.CREATED, '%M') as MONTH,
YEAR(T.CREATED) as YEAR,
count(*) as OPEN
from HD_TICKET T
group by MONTH, YEAR
order by YEAR desc, str_to_date(MONTH,'%M') desc
____________________________________________________
Simplified version - only tickets with an Open status for the current year
select date_format(T.CREATED, '%M') as MONTH,
YEAR(T.CREATED) as YEAR,
count(*) as OPEN
from HD_TICKET T
where YEAR(T.CREATED) = date_format(curdate(), '%Y')
group by MONTH, YEAR
order by YEAR desc, str_to_date(MONTH,'%M') desc
____________________________________________________
Hope that helps!
John - jverbosk 11 years ago
Ticket Count by Owner (Current Year)
and have it changed to:
Ticket County by Category (Current Year)
?
Every example I have found with suggestions to make changes to the code keeps resulting in SQL errors that the column doesn't exist. Any help would be greatly appreciated. - afort 8 years ago