CanNeverThinkOfaName
Programmer
Hi
I've been banging my head against the wall for this one for way too long so I really am hoping someone else can see a solution for me!
To start with here is the base data...there are 4 scenarios I am trying to cover in my sql query and the rows below cover all 4
This is all to do with call (phone) records!
In scenario 1, caller 69900548187 (originator) rang caller 20151241 (terminatior)
but 20151241 had call forwarding set up so the call forwarded to 69900255577 (lines 3 and 4 of scenario 1)
69900255577 didnt answer so it went to voicemail (lines 5 and 6 of scenario 1)
in scenario 2, the caller rang someone who had call forwarding set on. (2 call parts - part 1 the call part 2 the forwarded call)
in scenario 3, the caller rang someone which went to voicemail.(2 call parts - part 1 the call part 2 the voicemail)
in scenario 4, the caller rang someone who answered (I wish they were all that way!)
SO my problem is I need to count how many calls where made- from these 16 lines, only 4 calls were actually made (there are 2 legs to each call and I dont want to count fowarding/voicemail as being a seperate call)
I need to get my sql code to return me a count of 4 so I need to cater for all these scenario's in my 1 sql statement.
what I have come up with is this but it just never finishes running as its too complex (takes 25 mins to return the count for just 2 days worth of data!!)
The last bit in the 'or' statement is too intensive but I can't see any other way to return scenario 4 without it (the most simplest one)
I'm using Oracle 10g.
Has anyone any hints or tips for me please?!!
Thanks in advance!
I've been banging my head against the wall for this one for way too long so I really am hoping someone else can see a solution for me!
To start with here is the base data...there are 4 scenarios I am trying to cover in my sql query and the rows below cover all 4
Code:
create table cdr
( starttime varchar2(50),
userid varchar2(100),
direction varchar2(20),
localcallid varchar2(20),
remotecallid varchar2(20),
relatedcallid varchar2(20),
transfer_relatedcallid varchar2(20)
)
;
--scenario 1
insert into cdr values('02/02/2008 00:00:05','69900548187@x','Originating','4705114:0','4705115:0','','');
insert into cdr values('02/02/2008 00:00:05','20151241@x','Terminating','4705115:0','4705114:0','','');
insert into cdr values('02/02/2008 00:00:05','20151241@x','Originating','4705115:0A','4705116:0','4705115:0','');
insert into cdr values('02/02/2008 00:00:05','69900255577@x','Terminating','4705116:0','4705115:0A','','4705116:0A');
insert into cdr values('02/02/2008 00:00:11','69900255577@x','Originating','4705116:0A','4705118:0','','4705116:0');
insert into cdr values('02/02/2008 00:00:11','140212125_VMR@x','Terminating','4705118:0','4705116:0A','','');
--scenario 2
insert into cdr values('02/02/2008 02:02:03','69900078096@x','Originating','4706880:0','4706881:0','','');
insert into cdr values('02/02/2008 02:02:03','69900046976@x','Terminating','4706881:0','4706880:0','','4706881:0A');
insert into cdr values('02/02/2008 02:02:03','69900046976@x','Originating','4706881:0A','4706882:0','','4706881:0');
insert into cdr values('02/02/2008 02:02:03','132526763_VMR@x','Terminating','4706882:0','4706881:0A','','');
--scenario 3
insert into cdr values('02/02/2008 00:39:07','202822780@x','Originating','4705790:0','4705791:0','','');
insert into cdr values('02/02/2008 00:39:07','202821542@x','Terminating','4705791:0','4705790:0','','');
insert into cdr values('02/02/2008 00:39:07','202821542@x','Originating','4705791:0A','4705792:0','4705791:0','');
insert into cdr values('02/02/2008 00:39:07','69900312616@x','Terminating','4705792:0','4705791:0A','','');
--scenario 4
insert into cdr values('02/02/2008 00:27:51','2086082@x','Originating','4705550:0','4705551:0','','');
insert into cdr values('02/02/2008 00:27:51','2086214@x','Terminating','4705551:0','4705550:0','','');
This is all to do with call (phone) records!
In scenario 1, caller 69900548187 (originator) rang caller 20151241 (terminatior)
but 20151241 had call forwarding set up so the call forwarded to 69900255577 (lines 3 and 4 of scenario 1)
69900255577 didnt answer so it went to voicemail (lines 5 and 6 of scenario 1)
in scenario 2, the caller rang someone who had call forwarding set on. (2 call parts - part 1 the call part 2 the forwarded call)
in scenario 3, the caller rang someone which went to voicemail.(2 call parts - part 1 the call part 2 the voicemail)
in scenario 4, the caller rang someone who answered (I wish they were all that way!)
SO my problem is I need to count how many calls where made- from these 16 lines, only 4 calls were actually made (there are 2 legs to each call and I dont want to count fowarding/voicemail as being a seperate call)
I need to get my sql code to return me a count of 4 so I need to cater for all these scenario's in my 1 sql statement.
what I have come up with is this but it just never finishes running as its too complex (takes 25 mins to return the count for just 2 days worth of data!!)
Code:
select cn.starttime,
cn.userid, cnb.userid,
cn.direction , cn.localcallid, cn.remotecallid, cn.relatedcallid, cn.transfer_relatedcallid,cnb.localcallid,
cnb.remotecallid, cnb.relatedcallid, cnb.transfer_relatedcallid, cnb.transfer_relatedcallid
from cdr cn, cdr cnb
where cn.localcallid = cnb.remotecallid
and cn.direction = 'Terminating'
and (
(cnb.relatedcallid is null
and cnb.TRANSFER_RELATEDCALLID is not null) -- scenario 1 and 2
or
(cn.TRANSFER_RELATEDCALLID is null
and cnb.TRANSFER_RELATEDCALLID is null
and cnb.relatedcallid is not null) -- scenario 3
or (
((select relatedcallid from cdr_normal cn1 where cn1.relatedcallid = cn.localcallid) is null)
and (select transfer_relatedcallid from cdr_normal cn1 where cn1.transfer_relatedcallid = cn.localcallid) is null) -- scenario 4
)
order by cn.localcallid
Code:
(((select relatedcallid from cdr_normal cn1 where cn1.relatedcallid = cn.localcallid) is null)
and (select transfer_relatedcallid from cdr_normal cn1 where cn1.transfer_relatedcallid = cn.localcallid) is null))
I'm using Oracle 10g.
Has anyone any hints or tips for me please?!!
Thanks in advance!