2017-09-15 4 views
-1

Ich habe die folgende Abfrage, die Zeit zum Ausführen dauert. Ich denke, es ist aufgrund der Gruppe von. Kann jemand diese Abfrage ändern und Abfrage ausführen, ohne GroupBy zu verwenden, aber das Ergebnis der Ausgabe sollte identisch sein.langsame Abfrage Ausführung

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 
+0

setzen Sie Ihre Filter versuchen, wenn u Aggregation müssen dann u kann es nicht vermeiden, denke ich, ... vor allem brauchen wir Plan erklären und Tabellenzeilen zählen, DDL, (vielleicht für die apps.SCHL_ORDER_DETAILS_V Tabelle oder Ansicht) – Thomas

Antwort

0

bin ich nicht sicher, ob es hilft - aber Sie können subquery in

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