Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Group by is slow with Order by

3154057Aug 18 2017 — edited Aug 22 2017

Hi All,

I am running following SQL, which it taking almost 4-5 seconds and returning only 18 records.

SELECT

   SUM(TOTAL_AMOUNT) C1,

   a.LEVEL2_ENAME AS c2,

   c.CURR_YEARMO AS c3

FROM TERRITORY_PRESET_MSNP a,

   CV_RESTATED_MSNP b

   LEFT OUTER JOIN

   MONTH_D c

   ON b.YEARMO = c.CURR_YEARMO,

   PRODUCT_OFFERING d

WHERE (    b.PO_ID = d.ROW_ID

    AND b.DATASOURCE_ID = 10

    AND b.YEARMO = 201704

    AND b.OWNER_TERR_ID = a.TERR_ID

    AND c.CURR_YEARMO = 201704

    AND a.YEARMO = 201706

GROUP BY c.CURR_YEARMO, a.LEVEL2_ENAME

ORDER BY C3, C2;

If I remove the ORDER BY clause it is returning results in 1 second.

Can you guide me what is the issue?

~Shalini

This post has been answered by Nimish Garg on Aug 18 2017
Jump to Answer

Comments

838162

Please help me.

1 - 1
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Sep 15 2017
Added on Aug 18 2017
9 comments
1,337 views