Report on tickets missing work
I'm trying to come up with a quick report that can tell me when a support ticket is closed, but has no work attached to it. I've started with a simple query that returns all tickets (open or closed), but I'm getting the reverse of what I'm looking for.
The following query will return all tickets WITH work, instead of all tickets WITHOUT work. I'm pretty much trying to say "If the Ticket ID from HD_TICKET doesn't show up in HD_WORK, return that information."
SELECT T.ID
FROM HD_TICKET T
LEFT JOIN
HD_WORK W
ON W.HD_TICKET_ID = T.ID
WHERE W.HD_TICKET_ID IS NOT NULL
I know I'm probably missing something simple, but I just can't get it sorted. Thanks in advance if anyone has any input.
EDIT:
Got it figured out!
SELECT T.ID AS TICKET, T.CREATED as CREATED,
ifnull((select FULL_NAME from USER where T.OWNER_ID = USER.ID),' Unassigned') as OWNER_NAME
FROM HD_TICKET T
LEFT JOIN HD_WORK W ON W.HD_TICKET_ID = T.ID
LEFT JOIN HD_STATUS on HD_STATUS_ID = HD_STATUS.ID
WHERE NOT EXISTS (SELECT 1 FROM HD_WORK W WHERE W.HD_TICKET_ID = T.ID)
AND HD_STATUS.STATE = 'closed'
ORDER BY T.ID
0 Comments
[ + ] Show comments
Answers (0)
Please log in to answer
Be the first to answer this question