慢查询执行

时间:2017-09-15 09:42:49

标签: oracle

我有以下查询需要时间来执行。我认为这是由于Group By。任何人都可以在不使用GroupBy的情况下修改此查询并执行查询,但输出结果应该相同。

SELECT order_id,
       sum(item_total)item_total,
       sum(discount)discount,
       sum(shipping_amount)shipping_amount,
       sum(tax_total)tax_total,
       sum(grand_total)grand_total,
       order_status,
       order_date,
       store_label,
       promotion_key,
       store_identifier,
       ship_party_name,
       ship_address1,
       ship_address2,
       ship_city,
       ship_zip,
       ship_state,
       ship_to_phone,
       ship_type,
       bill_party_name,
       bill_address1,
       bill_address2,
       bill_city,
       bill_state,
       bill_zip,
       bill_to_phone,
       bill_to_email,
       card_brand,
       credit_card_number
FROM apps.SCHL_ORDER_DETAILS_V
WHERE UCN=?
  AND order_id=?
GROUP BY order_id,
         order_status,
         order_date,
         store_label,
         promotion_key,
         store_identifier,
         bill_party_name,
         bill_address1,
         bill_address2,
         bill_city,
         bill_state,
         bill_zip,
         bill_to_phone,
         bill_to_email,
         card_brand,
         credit_card_number,
         ship_party_name,
         ship_address1,
         ship_address2,
         ship_city,
         ship_zip,
         ship_state,
         ship_to_phone,
         ship_type,
         store_label

1 个答案:

答案 0 :(得分:0)

我不确定它是否有帮助 - 但您可以尝试将过滤器放入子查询

select 
order_id,
       sum(item_total)item_total,
       sum(discount)discount,
       sum(shipping_amount)shipping_amount,
       sum(tax_total)tax_total,
       sum(grand_total)grand_total,
       order_status,
       order_date,
       store_label,
       promotion_key,
       store_identifier,
       ship_party_name,
       ship_address1,
       ship_address2,
       ship_city,
       ship_zip,
       ship_state,
       ship_to_phone,
       ship_type,
       bill_party_name,
       bill_address1,
       bill_address2,
       bill_city,
       bill_state,
       bill_zip,
       bill_to_phone,
       bill_to_email,
       card_brand,
       credit_card_number
from (
SELECT order_id,
       item_total,
       discount,
       shipping_amount,
       tax_total,
       grand_total,
       order_status,
       order_date,
       store_label,
       promotion_key,
       store_identifier,
       ship_party_name,
       ship_address1,
       ship_address2,
       ship_city,
       ship_zip,
       ship_state,
       ship_to_phone,
       ship_type,
       bill_party_name,
       bill_address1,
       bill_address2,
       bill_city,
       bill_state,
       bill_zip,
       bill_to_phone,
       bill_to_email,
       card_brand,
       credit_card_number
    FROM apps.SCHL_ORDER_DETAILS_V
    WHERE UCN=?
      AND order_id=?
   )
    GROUP BY order_id,
             order_status,
             order_date,
             store_label,
             promotion_key,
             store_identifier,
             bill_party_name,
             bill_address1,
             bill_address2,
             bill_city,
             bill_state,
             bill_zip,
             bill_to_phone,
             bill_to_email,
             card_brand,
             credit_card_number,
             ship_party_name,
             ship_address1,
             ship_address2,
             ship_city,
             ship_zip,
             ship_state,
             ship_to_phone,
             ship_type,
             store_label