2017-09-15 7 views
-1

私は次のクエリを実行しています。これは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 
+0

にあなたのフィルタを入れて試すことができます計画を説明し、テーブルの行数、DDL(おそらくapps.SCHL_ORDER_DETAILS_Vテーブル、またはビューの場合) – Thomas

答えて

0

私はそれができますかはわからない - しかし、あなたはuが集約を必要とするならば、uは、私たちが必要とするすべての最初の...私は考えてそれを避けることはできませんサブクエリ

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 
関連する問題