Оптимизируйте Oracle Query, чтобы избежать затрат времени - PullRequest
0 голосов
/ 17 октября 2019

Пожалуйста, оптимизируйте запрос.

select * from (
     select 'spent' "Type",
     count(*) "Today Cases", sum(av.BILLING_AMOUNT) "Today Total Amount"
     from action_list al, v_autho_activity_view av
     where trunc(av.INTERNAL_TRANSMISSION_TIME) = trunc(sysdate-1)
       and av.ACTION_CODE = al.code_action
       and al.action_flag = 'A'
       and av.CARD_ACCEPTOR_ID <> '09218001'
    and av.MESSAGE_TYPE in (1100,1120)), 
    (select 
     count(*) "Last Month Cases", sum(av.BILLING_AMOUNT) "Last Month Total Amount"
     from action_list al, v_autho_activity_view av
     where trunc(av.INTERNAL_TRANSMISSION_TIME) = add_months(trunc(sysdate) - 1, -1)
       and av.ACTION_CODE = al.code_action
       and al.action_flag = 'A'
       and av.CARD_ACCEPTOR_ID <> '09218001'
    and av.MESSAGE_TYPE in (1100,1120)), 
    (select 
     count(*) "MTD Cases", sum(av.BILLING_AMOUNT) "MTD Total Amount"
     from action_list al, v_autho_activity_view av
     where trunc(av.INTERNAL_TRANSMISSION_TIME)  between
                   last_day(add_months(trunc(sysdate) - 1, -1)) + 1 and
                   trunc(sysdate) - 1
       and av.ACTION_CODE = al.code_action
       and al.action_flag = 'A'
       and av.CARD_ACCEPTOR_ID <> '09218001'
    and av.MESSAGE_TYPE in (1100,1120)),
    (select 
     count(*) "Last MTD Cases", sum(av.BILLING_AMOUNT) "Last MTD Total Amount"
     from action_list al, v_autho_activity_view av
     where trunc(av.INTERNAL_TRANSMISSION_TIME)  between
                   last_day(add_months(trunc(sysdate) - 1, -2)) + 1 and
                   add_months(trunc(sysdate) - 1, -1)
       and av.ACTION_CODE = al.code_action
       and al.action_flag = 'A'
       and av.CARD_ACCEPTOR_ID <> '09218001'
    and av.MESSAGE_TYPE in (1100,1120))
    UNION
    select *
      from (select 'Payments' "Type",
                   count(*) "Today Cases",
                   sum(tr.BILLING_AMOUNT) "Today Total Amount"
              from v_cr_transaction_view tr
             where trunc(tr.TRANSACTION_DATE) = trunc(sysdate - 1)
               and tr.TRANSACTION_CODE in ('6D', '6A', '6E', '6M', '65', '6K')),
           (select count(*) "Last Month Cases",
                   sum(tr.BILLING_AMOUNT) "Last Month Total Amount"
              from v_cr_transaction_view tr
             where trunc(tr.TRANSACTION_DATE) =
                   add_months(trunc(sysdate) - 1, -1)
               and tr.TRANSACTION_CODE in ('6D', '6A', '6E', '6M', '65', '6K')),
           (select count(*) "MTD Cases",
                   sum(tr.BILLING_AMOUNT) "MTD Total Amount"
              from v_cr_transaction_view tr
             where trunc(tr.TRANSACTION_DATE) between
                   last_day(add_months(trunc(sysdate) - 1, -1)) + 1 and
                   trunc(sysdate) - 1
               and tr.TRANSACTION_CODE in ('6D', '6A', '6E', '6M', '65', '6K')),
           (select count(*) "Last MTD Cases",
                   sum(tr.BILLING_AMOUNT) "Last MTD Total Amount"
              from v_cr_transaction_view tr
             where trunc(tr.TRANSACTION_DATE) between
                   last_day(add_months(trunc(sysdate) - 1, -2)) + 1 and
                   add_months(trunc(sysdate) - 1, -1)
               and tr.TRANSACTION_CODE in ('6D', '6A', '6E', '6M', '65', '6K'))
...