/build/static/layout/Breadcrumb_cap_w.png

How can I display open tickets by queue with queues having zero tickets.

Need to run KACE Helpdesk report with open tickets by queues but also need to display queues having zero tickets.

Example:
Queue1       10
Queue2        20
Queue3        0
Queue4        10

I have SQL displaying queues with tickets open but cant make the rest of the queues to display zero's (0's).

  SELECT
HD_QUEUE.NAME AS department,
IFNULL(COUNT(HD_TICKET.ID),0) AS count
FROM HD_TICKET
LEFT JOIN HD_STATUS on HD_STATUS_ID = HD_STATUS.ID 
JOIN HD_QUEUE on HD_QUEUE.ID = HD_TICKET.HD_QUEUE_ID
WHERE (HD_TICKET.HD_QUEUE_ID in (58,63,60,47,33,67,59,62,64)) AND (HD_STATUS.STATE = 'stalled' OR HD_STATUS.STATE = 'opened')
GROUP BY department

Thanks in advance for the help.

0 Comments   [ + ] Show comments

Answers (1)

Answer Summary:
grayematter answer: SELECT HD_QUEUE.NAME AS department, IFNULL(tc.ticket_count, 0) AS count FROM HD_QUEUE LEFT JOIN (SELECT q.id, COUNT(t.ID) AS ticket_count FROM HD_TICKET t LEFT JOIN HD_STATUS ON HD_STATUS_ID = HD_STATUS.ID LEFT JOIN HD_QUEUE q ON q.ID = t.HD_QUEUE_ID WHERE (HD_STATUS.STATE = 'stalled' OR HD_STATUS.STATE = 'opened') GROUP BY t.HD_QUEUE_ID) tc ON tc.id = HD_QUEUE.ID WHERE (HD_QUEUE.ID in (58,63,60,47,33,67,59,62,64)) ORDER BY department
Posted by: grayematter 9 years ago
5th Degree Black Belt
1
Give this a try:

SELECT 
    HD_QUEUE.NAME AS department,
    IFFNULL(tc.ticket_count, 0) AS count
FROM
    HD_QUEUE
        LEFT JOIN
    (SELECT 
        q.id, COUNT(t.ID) AS ticket_count
    FROM
        HD_TICKET t
    LEFT JOIN HD_STATUS ON HD_STATUS_ID = HD_STATUS.ID
    LEFT JOIN HD_QUEUE q ON q.ID = t.HD_QUEUE_ID
    WHERE
        (HD_STATUS.STATE = 'stalled'
            OR HD_STATUS.STATE = 'opened')
    GROUP BY t.HD_QUEUE_ID) tc ON tc.id = HD_QUEUE.ID
WHERE (HD_QUEUE.ID in (58,63,60,47,33,67,59,62,64))
ORDER BY department


Comments:
  • Just removed an extra F in IFFNULL and Worked Great!! Thanks grayematter. - rguerrer93 9 years ago

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ