K1000 Reporting - SQL "Count" Query
Hello,
I am trying to generate a report in Kace that counts the total number of tickets created within a month based on custom fields values in all our queues. Below is the custom sql query i have generated so far however stuck on how/where to input the "count" to account for how many number of tickets where created with Custom fields 1 and Custom field 2 in the last 30 days. Any assistance will be much appreciated, thanks in advance.
SELECT HD_TICKET.CREATED, HD_STATUS.NAME AS STATUS, HD_TICKET.ID, HD_TICKET.CUSTOM_FIELD_VALUE2, HD_TICKET.CUSTOM_FIELD_VALUE1 FROM HD_TICKET JOIN HD_STATUS ON (HD_STATUS.ID = HD_TICKET.HD_STATUS_ID) WHERE (HD_TICKET.HD_QUEUE_ID in (5,2,8,9,12,14,18,16,1,15,10,11,3,13,17,25,20)) AND ((TIMESTAMP(HD_TICKET.CREATED) <= NOW() AND TIMESTAMP(HD_TICKET.CREATED) > DATE_SUB(NOW(),INTERVAL 30 DAY))) ORDER BY CREATED
Answers (0)
Be the first to answer this question
Tickets with any value in Custom1 or Custom2: 45
Are you looking for counts grouped by the values of custom1 and custom2 (a data cube)? Such as:
Custom1 Custom2 Count
value_a value_b 3
value_a Value_c 5
value_d value_b 10
value_d value_e 14 - grayematter 11 years ago
Thanks, - k100user 11 years ago
SELECT HD_STATUS.NAME AS STATUS,
HD_TICKET.CUSTOM_FIELD_VALUE2,
HD_TICKET.CUSTOM_FIELD_VALUE1,
count(*) as count_of_both
FROM HD_TICKET
JOIN HD_STATUS ON (HD_STATUS.ID = HD_TICKET.HD_STATUS_ID)
WHERE (HD_TICKET.HD_QUEUE_ID in (5,2,8,9,12,14,18,16,1,15,10,11,3,13,17,25,20))
AND ((TIMESTAMP(HD_TICKET.CREATED) <= NOW() AND TIMESTAMP(HD_TICKET.CREATED) > DATE_SUB(NOW(),INTERVAL 30 DAY)))
GROUP BY HD_STATUS.NAME, HD_TICKET.CUSTOM_FIELD_VALUE2, HD_TICKET.CUSTOM_FIELD_VALUE1
ORDER BY HD_STATUS.NAME, HD_TICKET.CUSTOM_FIELD_VALUE2, HD_TICKET.CUSTOM_FIELD_VALUE1
Something like this will give you data that you can import into an excel pivot table. You can then slice and dice the data as you wish. If you want to add the option to view counts by queue, add HD_TICKET.HD_QUEUE_ID to the select, group by, and order by clauses. - grayematter 11 years ago
Thanks - k100user 11 years ago