N
Noozer
I have the follow query that returns all the details pertaining to each
ticket, plus how many actions exist for that ticket...
SELECT * FROM Tickets
LEFT JOIN [SELECT TicketKeyLink, COUNT(*) AS ActionCount FROM Actions GROUP
BY Actions.TicketKeyLink]. AS b ON Tickets.TicketKey=b.TicketKeyLink;
....I need to be able to filter the results so that the only tickets that are
returned are the ones that I have actioned (Actions.ActionBy='8213')
So, for the output I want Tickets.*, ActionCount (number), ActionedByMe
(boolean)
I cannot, for the life of me, figure out how to write this query. I think
it's just the way I'm trying to use "EXISTS", but I'm honestly too confused
at this point to know what to do.
I'm guessing that it would be something like...
SELECT * FROM (Tickets
LEFT JOIN [SELECT TicketKeyLink, COUNT(*) AS ActionCount FROM Actions GROUP
BY Actions.TicketKeyLink]. AS b ON Tickets.TicketKey=b.TicketKeyLink)
LEFT JOIN [SELECT TicketKeyLink, EXISTS( SELECT * FROM Actions WHERE
ActionBy='8213' GROUP BY Actions.TicketKeyLink) AS ActionedByMe]. AS c ON
Tickets.TicketKey=c.TicketKeyLink;
ticket, plus how many actions exist for that ticket...
SELECT * FROM Tickets
LEFT JOIN [SELECT TicketKeyLink, COUNT(*) AS ActionCount FROM Actions GROUP
BY Actions.TicketKeyLink]. AS b ON Tickets.TicketKey=b.TicketKeyLink;
....I need to be able to filter the results so that the only tickets that are
returned are the ones that I have actioned (Actions.ActionBy='8213')
So, for the output I want Tickets.*, ActionCount (number), ActionedByMe
(boolean)
I cannot, for the life of me, figure out how to write this query. I think
it's just the way I'm trying to use "EXISTS", but I'm honestly too confused
at this point to know what to do.
I'm guessing that it would be something like...
SELECT * FROM (Tickets
LEFT JOIN [SELECT TicketKeyLink, COUNT(*) AS ActionCount FROM Actions GROUP
BY Actions.TicketKeyLink]. AS b ON Tickets.TicketKey=b.TicketKeyLink)
LEFT JOIN [SELECT TicketKeyLink, EXISTS( SELECT * FROM Actions WHERE
ActionBy='8213' GROUP BY Actions.TicketKeyLink) AS ActionedByMe]. AS c ON
Tickets.TicketKey=c.TicketKeyLink;