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 式を使用すると、最初の選択が null でない場合に追加の選択が切り取られます...

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

私の解決策は、それが本当にパフォーマンスを向上させるかどうかわかりません...

REGEX で検索し、該当する番号を取得後、表示の置換を行います。

反対側では、交換を 1 つ省いてLTRIMinstat を使用できます。最初に「(」、次に「)」を置き換え、次に「+44」を置き換え、最後に LTRIM を使用してスペースを取り除きます。

于 2012-10-03T13:58:26.420 に答える
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 に答える