I knew that stackoverflow would help me, besides finding out what a "favorite software cartoon" is: P
That was the accepted answer: Bill Carvin
Thank you all for your help (I would like to vote twice for you)
My request turned out like this (this is real)
SELECT accepted.folio, COALESCE( inprog.activityin, accepted.activityin ) as activityin, inprog.participantin, accepted.completiondate FROM performance accepted LEFT OUTER JOIN performance inprog ON( accepted.folio = inprog.folio AND inprog.ACTIVITYIN IN ( 4, 435 )
Now I just need to join the other tables for a readable report.
ORIGINAL MAILHello.
I'm afraid about 6 hours. now with a DB request (my long-term enemy)
I have a data table with fields such as:
table performance( identifier varchar, activity number, participant number, closedate date, )
Used to track ticket history
Identifier : Customer Identifier (NAF0000001)
activity : this is fk where is the ticket (new, in_progress, rejected, closed, etc.)
participant : is fk of the person who is visiting the ticket at that moment
closedate : this is the completion date of this operation.
EDIT: I should have said โcompletion,โ not closing. This is the date the action was completed, not necessarily when the ticket was closed.
For example, a typical story could be:
identifier | activity | participant | closedate
-------------------------------------------
NA00000001 | 1 | 1 | 2008/10/08 15:00 |
-------------------------------------------
NA00000001 | 2 | 2 | 2008/10/08 15:20 |
-------------------------------------------
NA00000001 | 3 | 2 | 2008/10/08 15:40 |
-------------------------------------------
NA00000001 | 4 | 4 | 2008/10/08 17:05 |
-------------------------------------------
And party 1 = jonh, 2 = scott, 3 = mike, 4 = rob
and activties 1 = new, 2 = inprogress, 3 = waitingforapproval, 4 = closed
etc .. And dozens of other irrelevant information.
Well, my problem is as follows.
I managed to create a request where I can find out when the ticket was open and closed
This is true:
select a.identifier, a.participant, a.closedate as start, b.closedate as finish from performance a, performance b where a.activity = 1
But I donโt know which tickets are not closed and who visits them.
So far, I have something like this:
select a.identifier, a.participant, a.closedate as start from performance a where a.activity = 1 -- new and a.identifier not in ( select identifier from performance where activity = 4 ) --closed
This gives me everyone who has a beginning (new = 1) but not closed (closed = 4)
But the big problem is that he prints the member who opened the ticket, but I need the member who visits him. Therefore, I am adding inprogress activity to the request.
select a.identifier, a.participant, a.closedate as start from performance a, performance b where a.activity = 1
But not all the lines that are in the "new" are "inprogress", and with this request I throw them all.
I need to show all inprogress participants, and if the ticket is not inprogress, it will be displayed as empty.
Somthing like
identifier | activity | participant | closedate
-------------------------------------------
NA00000002 | 1 | | 2008/10/08 15: 00 |
-------------------------------------------
NA00000003 | 1 | | 2008/10/08 15: 20 |
-------------------------------------------
NA00000004 | 1 | | 2008/10/08 15: 40 |
-------------------------------------------
NA00000005 | 2 | 4 | 2008/10/08 15:40 |
-------------------------------------------
NA00000006 | 2 | 4 | 2008/10/08 15:40 |
In this case
NA002, NA003 and NA004 are in the "new", so no members are displayed
While
NA005 and NA006 are "inprgress (act = 2)" and rob (member 4) is participating
So, I remember that this thing was called a left outer join or something like that, but I never understand it. I would like to know how I can get identifiers that are "inprogress" and "new" and which are not closed.
Probably having a little rest, I can clear my mind. If anyone knows how to do this, I would appreciate it.
By the way, I tried:
select a.identifier, a.participant, a.closedate as start from performance a left outer join performance b on b.identifier = a.identifier where a.activity = 1
But it gives the same result as the previous one (discards only in "new" records)