1

下面的代码运行时间太长。我知道这是代码:

case when (select (concat(alias,' - ',firm))
        from publiccontact where replace(replace(replace(replace(businessnumber,'+44 (','0'),') ',''),'+44','0'),')','') =  tax.callerid1 and businessnumber <> ''
            limit 1
            ) is not null then
            (select (concat(alias,' - ',firm))
        from publiccontact where replace(replace(replace(replace(businessnumber,'+44 (','0'),') ',''),'+44','0'),')','') =  tax.callerid1 and businessnumber <> ''
            limit 1
            ) else (select (concat(alias,' - ',firm))
        from publiccontact where replace(replace(replace(replace(mobilenumber,'+44 (','0'),') ',''),'+44','0'),')','') =  tax.callerid1 and mobilenumber <> ''
            limit 1
            )
    end as callername,

我可以让我的案例和子选择更有效率吗?我的代码有效,但绝对没有效率。

select  date(instime) as date,
    Pkey as ID,
    subscriber as user,
    SUBSCRIBERNAME as userName,
    case when (select (concat(alias,' - ',firm))
        from publiccontact where replace(replace(replace(replace(businessnumber,'+44 (','0'),') ',''),'+44','0'),')','') =  tax.callerid1 and businessnumber <> ''
            limit 1
            ) is not null then
            (select (concat(alias,' - ',firm))
        from publiccontact where replace(replace(replace(replace(businessnumber,'+44 (','0'),') ',''),'+44','0'),')','') =  tax.callerid1 and businessnumber <> ''
            limit 1
            ) else (select (concat(alias,' - ',firm))
        from publiccontact where replace(replace(replace(replace(mobilenumber,'+44 (','0'),') ',''),'+44','0'),')','') =  tax.callerid1 and mobilenumber <> ''
            limit 1
            )
    end as callername,
    (select (concat(alias,' - ',firm))
        from publiccontact where replace(replace(replace(replace(businessnumber,'+44 (','0'),') ',''),'+44','0'),')','') =  tax.destinationnumber1 and businessnumber <> ''
            limit 1
            )
    as destinationname,
    case when direction = 1 then 'incoming' else 'outgoing' end as direction,
    case when CALLDESTINATION = 1 then 'public' else 'private' end as destination,
    startdate as StartDate,
    starttime as StartTime,
    duration as DuractionSec,
    TIMETOANSWER as TimeAnswerSec,
    TAXCHARGES as Charges,
    coalesce(callerid1,callerid2,'') as CallerID,
    coalesce(destinationnumber1,destinationnumber2,'') as DestinationNumber,
    ORIGINSUBSCRIBER as UserNumber,
    completed as CallCompleted,
    coalesce(case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 2123 then 'Incoming Call Transfered External' else null end,
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 1132 then 'Incoming Call Transfered External' else null end,
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 1131 then 'Incoming Call Transfered Interal' else null end,
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 1132 then 'Incoming Call Transfered Interal' else null end,
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 1233 then 'AMC Call Answered' else null end, 
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 2122 then 'Incoming DDI call answered by GSM' else null end,
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 1232 then 'AMCOutgoing' else null end,
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 2111 then 'OutgoingCallTransferedInternally' else null end,
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 2121 then 'OutgoingCallTransferedInternally' else null end,
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 2123 then 'OutgoingCallTransferedtoExternal' else null end,
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 1252 then 'IncomingCallPrivateNetworkCallShouldBeIgnored' else null end,
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 1143 then 'IncACDCallUnaws' else null end,
    case when concat(DIRECTION,CALLDESTINATION,CALLTYPE,CALLHANDLING) = 1142 then 'IncACDCallAnswered' else null end,'') as type

from taxticketitem tax;

亲切的问候

4

3 回答 3

1

MySQL 5.0 IFNULL

在第一个选择不为空的情况下,使用 IFNULL 表达式会删除一个额外的选择...

ifnull (
  (select (concat(alias,' - ',firm))
  from publiccontact where replace(replace(replace(replace(businessnumber,'+44 (','0'),') ',''),'+44','0'),')','') =  tax.callerid1 and businessnumber <> ''
  limit 1),   
  (select (concat(alias,' - ',firm))
  from publiccontact where replace(replace(replace(replace(mobilenumber,'+44 (','0'),') ',''),'+44','0'),')','') =  tax.callerid1 and mobilenumber <> ''
  limit 1)
)
于 2012-10-03T12:23:51.873 回答
0

我会为您的方向/呼叫目的地/呼叫类型/呼叫处理事物添加一个子查询。

select
   ...,
   CallDescription

from taxticketitem
    left join 
    (
       Select 2 as Direction, 1 as CallDestination, 2 as CallType, 3 as CallHandling, 'Incoming Call Transfered External' as CallDescription
       union 
       select 1,1,3,2, 'Incoming Call Transfered External'
       ...
    ) v
         on taxticketitem.Direction = v.Direction
         and taxticketitem.CallDestination = v.CallDestination
         and taxticketitem.CallType = v.CallType
         and taxticketitem.CallHandling = v.CallHandling
于 2012-10-03T12:30:33.637 回答
0

我的解决方案是,我不知道它是否真的带来了性能加...

使用 REGEX 进行搜索,并在检索到相应的数字后执行替换以显示。

另一方面,您可以备用一个替换并使用LTRIMinstat。首先替换 '(' 然后 ')',然后 '+44' 最后使用 LTRIM 来摆脱空间。

于 2012-10-03T13:58:26.420 回答