Sql for top sql

Dear DBAs
Application team has asked me to provide TOP Sql statements in testing database which can help them to improve code. Developer gave OEM top sql example from his last job.
Currently I do not have OEM installed. I am on 10.2.0.1.0 . I was thinking
to create a job to run sql and email everyday.
What sql can I use to generate that report ? What does OEM reports on when it show TOP Sql ?
Thanks

OEM will show you TOP sql by different catogories (each of which can be sorted) such as:
Disk Reads Per Execution
Buffer Gets Per Execution
Executions
Disk Reads
Buffer Gets
Buffer Gets Per Row
Buffer Cache Hit Ration
Sorts
Shareable memory
Rows Processed
CPU Time
Elapsed Time
Now having said that....just because the TOP sql statement is the TOP sql statement does not mean that anything needs tuned. Your developers should be examining their SQL using insite gained from reading articles and documentation.
Tuning use explain plan:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:231814117467
SQL Tuning
http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/sql_1016.htm#sthref1061
Automatic SQL Tuning
http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/sql_tune.htm#g42443
In particular:
12.2.4 Using SQL Tuning Advisor with Oracle Enterprise Manager
These links should point you in the right direction:
Of course there are books and Oracle classes that concentrate on these issues as well.
Regards
Tim Boles

Similar Messages

  • Custom report for TOP 10 CPU Utilization machines from any group in aggregation last seven days

    I want to create a custom report that contain list of TOP CPU Utilization of machines form any group.This report is create on last 7 days CPU utilization of all machine from a group.
    What  should be query for this report.

    Hi,
    Please refer to the links below:
    SQL Query for TOP 10 Average CPU
    https://social.technet.microsoft.com/Forums/systemcenter/en-US/8d9a2d0d-8761-4d1f-b194-b24aa65172e1/sql-query-for-top-10-average-cpu?forum=operationsmanagerreporting
    How to use Report Builder to create custom reports in SCOM 2007
    http://www.systemcentercentral.com/how-to-use-report-builder-to-create-custom-reports-in-scom-2007/
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]

  • Is rank() really better than rownum for top-n-queries?

    Several sources say that for Oracle databases rank() should be used instead of 'rownum <= n' for top-n-queries. But here we have an application, where we a lot of top-n queries are executed on a big table with several million rows and rank() has a quite bad performance. I get much better results when I use a query with rownum <= n but the programmer of the application doesn't want to change it in the software because of those articles about rank() and rownum. I wonder, whether it is possible, to find a better form of the rank()-query or an additional index, that gives me the same performance.
    To explain my case I created the following example (if you try it, be aware that depending on the size of your dba_objects view you might need up to half a gig free space in your tablespace for this example).
    create table big_objects
    as
    select
    ascii(m.alpha)*100000+o.object_id object_id,
    o.owner owner,
    o.object_type,
    m.alpha||'_'||o.object_name object_name,
    sysdate-400+mod(100*object_id+99*ascii(m.alpha),365)+24/(o.object_id+ascii(m.alpha)) created,
    o.status
    from
    (select distinct
    upper(substr(object_name,1,1)) alpha
    from
    sys.dba_objects
    where
    upper(substr(object_name,1,1)) between 'A' and 'Z') m,
    sys.dba_objects o
    order by
    object_name;
    create index bigindex_1 on big_objects (owner, object_type, created);
    analyze table big_objects compute statistics;
    So my table looks a bit like dba_objects but with much more rows and I made a synthetic "created" date which is more similar to my real case, where top-n means a date selection of the newest records from a certain type.
    Here is the size of the segments on an nearly empty 11gR2 database:
    select segment_name, bytes, blocks from sys.dba_segments where segment_name like 'BIG%'
    SEGMENT_NAME BYTES BLOCKS
    BIGINDEX_1 75497472 9216
    BIG_OBJECTS 142606336 17408
    On my database the example table has approx. 1,9 Mio rows:
    select count(*) from big_objects;
    COUNT(*)
    1884246
    and some 1,4% of those rows have owner = 'SYS' and object_type = 'INDEX'
    select
    count(*)
    from big_objects
    where owner = 'SYS'
    and object_type = 'INDEX';
    COUNT(*)
    25896
    But I want to find only the 10 newest indexes for the owner SYS. I think the typical rank() approach would be:
    select
    owner,
    object_type,
    object_name,
    object_id,
    status,
    created
    from
    ( select
    owner,
    object_type,
    object_name,
    object_id,
    status,
    created,
    rank() over (order by created desc) rnk
    from
    big_objects
    where
    owner = 'SYS'
    and object_type = 'INDEX')
    where rnk <= 10
    order by created asc;
    OWNER OBJECT_TYPE OBJECT_NAME OBJECT_ID STATUS CREATED
    SYS INDEX B_COLLELEMIND 6600515 VALID 15.04.2010 19:05:55
    SYS INDEX V_I_WRI$_OPTSTAT_IND_OBJ#_ST 8600466 VALID 15.04.2010 19:09:03
    SYS INDEX G_I_RLS 7100375 VALID 15.04.2010 19:23:55
    SYS INDEX V_I_DIR$SERVICE_UI 8600320 VALID 15.04.2010 19:31:33
    SYS INDEX L_I_TSM_DST2$ 7600308 VALID 15.04.2010 19:36:26
    SYS INDEX L_I_IDL_UB11 7600235 VALID 15.04.2010 19:57:34
    SYS INDEX V_I_VIEWTRCOL1 8600174 VALID 15.04.2010 20:19:21
    SYS INDEX L_I_TRIGGER2 7600162 VALID 15.04.2010 20:31:39
    SYS INDEX L_I_NTAB1 7600089 VALID 15.04.2010 21:35:53
    SYS INDEX B_I_SYN1 6600077 VALID 15.04.2010 22:08:07
    10 rows selected.
    Elapsed: 00:00:00.22
    Execution Plan
    Plan hash value: 2911012437
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1427 | 188K| 1400 (1)| 00:00:17 |
    | 1 | SORT ORDER BY | | 1427 | 188K| 1400 (1)| 00:00:17 |
    |* 2 | VIEW | | 1427 | 188K| 1399 (1)| 00:00:17 |
    |* 3 | WINDOW SORT PUSHED RANK | | 1427 | 79912 | 1399 (1)| 00:00:17 |
    | 4 | TABLE ACCESS BY INDEX ROWID| BIG_OBJECTS | 1427 | 79912 | 1398 (0)| 00:00:17 |
    |* 5 | INDEX RANGE SCAN | BIGINDEX_1 | 1427 | | 9 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    2 - filter("RNK"<=10)
    3 - filter(RANK() OVER ( ORDER BY INTERNAL_FUNCTION("CREATED") DESC )<=10)
    5 - access("OWNER"='SYS' AND "OBJECT_TYPE"='INDEX')
    Statistics
    1 recursive calls
    0 db block gets
    25870 consistent gets
    0 physical reads
    0 redo size
    1281 bytes sent via SQL*Net to client
    524 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    2 sorts (memory)
    0 sorts (disk)
    10 rows processed
    As from the index only the first two columns are used, all the 25896 records that I found above are read and sorted just to find the ten newest ones. Many unnecessary blocks are read and luckily all needed database blocks were in memory already. In our real case quite often a lot of physical reads are performed, which makes the performance of the application even worse.
    In my following example with a "rownum <= 10" all three columns of the index are used and the number of block gets is much, much smaller than in the rank() example.
    select
    owner,
    object_type,
    object_name,
    object_id,
    status,
    created
    from
    big_objects
    where
    (owner, object_type, created)
    in
    ( select
    owner,
    object_type,
    created
    from
    ( select /*+ first_rows(10) */
    owner,
    object_type,
    created
    from
    big_objects
    where
    owner = 'SYS'
    and object_type = 'INDEX'
    order by
    owner,
    object_type,
    created desc
    where rownum <= 10
    order by created asc;
    OWNER OBJECT_TYPE OBJECT_NAME OBJECT_ID STATUS CREATED
    SYS INDEX B_COLLELEMIND 6600515 VALID 15.04.2010 19:05:55
    SYS INDEX V_I_WRI$_OPTSTAT_IND_OBJ#_ST 8600466 VALID 15.04.2010 19:09:03
    SYS INDEX G_I_RLS 7100375 VALID 15.04.2010 19:23:55
    SYS INDEX V_I_DIR$SERVICE_UI 8600320 VALID 15.04.2010 19:31:33
    SYS INDEX L_I_TSM_DST2$ 7600308 VALID 15.04.2010 19:36:26
    SYS INDEX L_I_IDL_UB11 7600235 VALID 15.04.2010 19:57:34
    SYS INDEX V_I_VIEWTRCOL1 8600174 VALID 15.04.2010 20:19:21
    SYS INDEX L_I_TRIGGER2 7600162 VALID 15.04.2010 20:31:39
    SYS INDEX L_I_NTAB1 7600089 VALID 15.04.2010 21:35:53
    SYS INDEX B_I_SYN1 6600077 VALID 15.04.2010 22:08:07
    10 rows selected.
    Elapsed: 00:00:00.03
    Execution Plan
    Plan hash value: 3360237620
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 10 | 760 | 17 (0)| 00:00:01 |
    | 1 | SORT ORDER BY | | 10 | 760 | 17 (0)| 00:00:01 |
    | 2 | NESTED LOOPS | | | | | |
    | 3 | NESTED LOOPS | | 10 | 760 | 17 (0)| 00:00:01 |
    | 4 | VIEW | VW_NSO_1 | 10 | 200 | 2 (50)| 00:00:01 |
    | 5 | HASH UNIQUE | | 10 | 200 | 4 (25)| 00:00:01 |
    |* 6 | COUNT STOPKEY | | | | | |
    | 7 | VIEW | | 11 | 220 | 3 (0)| 00:00:01 |
    |* 8 | INDEX RANGE SCAN DESCENDING| BIGINDEX_1 | 1427 | 28540 | 3 (0)| 00:00:01 |
    |* 9 | INDEX RANGE SCAN | BIGINDEX_1 | 3 | | 2 (0)| 00:00:01 |
    | 10 | TABLE ACCESS BY INDEX ROWID | BIG_OBJECTS | 3 | 168 | 6 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    6 - filter(ROWNUM<=10)
    8 - access("OWNER"='SYS' AND "OBJECT_TYPE"='INDEX')
    9 - access("OWNER"="OWNER" AND "OBJECT_TYPE"="OBJECT_TYPE" AND "CREATED"="CREATED")
    Statistics
    1 recursive calls
    0 db block gets
    26 consistent gets
    0 physical reads
    0 redo size
    1281 bytes sent via SQL*Net to client
    524 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    1 sorts (memory)
    0 sorts (disk)
    10 rows processed
    I made this comparison with the Oracle versions 10.2 and 11.2 and the result was more or less the same. How can I change the rank() query in a way that only the small number of really needed blocks are read from the database?

    this was exactly the hint, I was looking for. Generally speaking hints are not the preferred way to go to tune queries. They can have nasty side-effects when data changes.
    Now the rank()-query is similar fast and much better to read than my fast one with three nested SELECTs.
    Your rownum query was needlessly complicated, and could be simplified to:
    select owner, object_type, object_name, object_id, status, created
    from (select owner, object_type, created
          from big_objects
          where owner = 'SYS' and
                object_type = 'INDEX'
          order by created desc)
    where rownum <= 10
    order by created ascand very likely get the same speed.
    One more question. How did you format those sql queries and results. When I copy/paste them into the editor of forums.oracle.com the format allways gets lost.To preserve formatting use {noformat}{noformat} before and after the section you want ot keep formatted.  In general, if you want to see how someone generated an effect, reply to the post and hit the quote original icon.  You will see all the formatting codes used in the original.
    John                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • On my iPad2, the buttons for Top Ten, Genres and New Releases are missing.  How do I get them back.

    On my iPad2, the buttons for Top Ten, Genres and New Releases are missing.  How do I get them back.

    If the menu bar is hidden then press the F10 key or hold down the Alt key, that should make the menu bar appear.
    * Go to "View > Toolbars" and check-mark "Menu Bar" with a click if you want to make that permanent
    See [[Menu bar is missing]]

  • ABAP routine for Top 10 material

    Hi All,
    I want to write an ABAP routine to get the Top 10 material as per their sales data.
    I have written a query where I have put condition (for Top 10).
    But I need to create an APD taking this query as base query. But conditions fail to filter data when it comes into a transactional ODS via an APD.
    So, I want to write a routine for transaformation of data (to get top 10 material based on their sales data) from base query to the transactional ODS.
    Please help me in writing this code.
    I am an amatuer in ABAP.
    Thanks,
    SB

    Hi ,
    You Need to read Data from the ODS for Top 10 Materials. I can give you the Logic but you would need to take the Help of an ABAPPER to convert this into the code
    Lets consider an ODS : ZODS which has a KF for Sales Data (ZKF)
    *****Define Internal Table ****************
    TABLES :
    /BIC/AZODS
    DATA:
    BEGIN of ITAB OCCURS 0,
        0material(18)       TYPE c,
        ZKF           like /bic/AZODS-/bic/ZKF,
    END OF ITAB.
    DATA:
    BEGIN of ITAB1 OCCURS 0,
        0material(18)       TYPE c,
        ZKF           like /bic/AZODS-/bic/ZKF,
    END OF ITAB1.
    Select MATERIAL, /BIC/ZKF from /BIC/AZODS into corresponding fields of ITAB1.
    LOOP AT ITAB1
    ITAB-MATERIAL = ITAB1-MATERIAL
    ITAB-ZKF= ITAB1-ZKF
    COLLECT ITAB.
    ENDLOOP.
    SORT ITAB ZKF.
    ************this will have the materials sorted take the first 10 Material Nos*****

  • ALV REPORT FOR TOP 10 CUSTOMERS

    hI,
    sap guys
    I need a help on alv. iam getting alv report. now i need to get TOP 10 customers in my report.
    My report having selling price , cost price , GP , GP% .
    Final internal table iam sorting based on Selling price. But how to Get the  Top 10 customers in my report.
    Plz help me..

    hi
    good day brother
    Before youve given the solution for top 20 cust as well as subtot.. iam getting a prob for one branch for subtot.
    Plz see the code..
    Ive dev the smart form for top 20 customers by Branch wise.. I have 17 branches in final itab.
    Every thing is fine except one branch for the Subtot.
    For getting  Subtot as well as Getting the top 20 cust.. the below code ive used.
    First branch like lt_br_out2 got 503 records
    lt_br_out3 == 213
    lt_br_out4 == 0
    lt_br_out5== 82
    lt_br_out6  ==89
    lt_br_out7 ==118
    lt_br_out8 == 45
    lt_br_out9 == 64
    lt_br_out10 == 53
    lt_br_out11 == 47
    lt_br_out12 == 56
    lt_br_out13 == 20 *************** "Problem with this internal table.
    lt_br_out14 ==170
    Problem: All Branches are getting subtotal and top 20 cust except " LT_BR_OUT13"...Before its going to cal the top 20 cust. its has only 20 records.
    Actually iam counting the top 20 cust as well as cal subtot and passing to Final Internal Table..
      SORT lt_br_out13  BY p1_a_p DESCENDING.
      CLEAR : lwa_out6.
      LOOP AT lt_br_out13 INTO lwa_out6.
        IF sy-tabix > 20.
          CLEAR: lwa_out6.
    ***adding the subtot
          lwa_out6-ort01 = lv_text.
          lwa_out6-p1_a_p = lv_brtot.
          lwa_out6-p2_a_p = lv_brtot1.
          lwa_out6-act_gross_p = lv_br.
          lwa_out6-act_gross_perc1 = lv_brperc1.
          APPEND  lwa_out6 TO lt_br_final.
          EXIT.
        ELSE.
    ***calc the sub tot
          lv_text    = 'Sub Total'.
          lv_brtot   = lv_brtot  + lwa_out6-p1_a_p.  " selling price
          lv_brtot1  = lv_brtot1 + lwa_out6-p2_a_p. " Cost price
          lv_br      = lv_brtot - lv_brtot1.
          lv_brperc   = ( lv_br / lv_brtot ) * 100.
          IF lv_brperc NE  0.
            WRITE lv_brperc TO lv_brperc1 LEFT-JUSTIFIED.
            CONCATENATE lv_brperc1 '%' INTO lv_brperc1 SEPARATED BY space.
          ENDIF.
          APPEND lwa_out6 TO lt_br_final.
        ENDIF.
      ENDLOOP.
    If i put sy-tabix >= 20, thne iam getting subtotal but iam getting only 19 records.
    Could u plz advice me.. Ive solved yesterday problem
    Regards

  • D3L "produce" error: unable to find attribute object for top node

    Hi
    I'm new to this forum, hope someone can help me with this because it's really been causing a headache for a few days now.
    I'm trying to deliver a flat file message with an interconnect standard ftp adapter. All the transformations go well but then i get this error message:
    oracle.oai.agent.adapter.technology.D3LException: [SmartQueueDispatcher] <struct id="GallupData" name="" comment="" ...>: unable to find attribute object for top node, got `[  stationId: 01
    startDate: 040801
    (messsage truncated)
    emission: 1
    ]' instead
         at oracle.oai.agent.adapter.technology.D3L.produce(D3L.java:391)
         at oracle.oai.agent.adapter.technology.TechBridge.messageReceived(TechBridge.java:876)
         at oracle.oai.agent.client.SmartQueueDispatcher.run(SmartQueueDispatcher.java:451)
         at java.lang.Thread.run(Unknown Source)
    The message is exactly 65570 bytes (in the format written to the log).
    Any help appreciated.
    Leon Simonsen

    I finally solved the problem: The name of the d3l xml file must be named with the name of the data type. Just thought i'd let anyone know.

  • What is ranking criteria for top iPhone apps?

    What is the ranking criteria used by iTunes for top iPhone apps -- premium and free? Is it just most downloaded? Also rankings are updated how frequently? Thank you!

    "Top" apps are defined by number of downloads. Seems to be updated "live" (it changes more than once a day sometimes, and since it is based on number of downloads, it's probably an automated process).

  • Dashboard for top Management.

    Dear all,
    i have to design dashboard for top management.my query is how i can decide that what general information a top management requires to be displayed on dashboardas i have no clear requirements...and am a fresher..i will give points if i got help on the same.

    Hi gaurav,
    Manager's Dashboard provides near-real-time performance metrics, enabling you to monitor plant operations at a glance. These user-selected metrics let you drill-down into supporting enterprise data to quickly understand manufacturing and operational activities throughout your plant. With access to key analytical data, you can then avoid or resolve problems by quickly taking corrective action.
    Some of the features and benefits of dashboards are
    Revenue Managementu2014provide metrics on future cash receipts and overall revenue performance
    Customer Shipment Performanceu2014display fulfillment information
    Manufacturing Performanceu2014get data on your manufacturing operations
    Inventory Management Effectivenessu2014provide summary information on inventory turns
    Supplier Performanceu2014provide summary and detailed information on supplier performance
    Cash and Capital Managementu2014display cash flow data
    So depending on these you can decide which content your organization wants, as your manager also what are the things he needs everyday for analysis. Also use the concept of MIS and EIS.
    Hope it will help.
    Reward Point if helpful.
    Thanks,
    Raja

  • Standard Query for Top 10 queries and Users

    Hi Experts,
    Is there any query which gives the details like ,
    1. Top 10 queries executed in a month
    2. Top 10 users ( By no of queries executed )
    Regards,
    Bhadri M.

    1. Top 10 queries executed in a month
    Use Query 0TCT_MCA1_Q0142.
    In this report you will have to filter variable BI Object to Queries and also it gives stats for the last 30 days, you have have to remove the SAP User exit variable in case you do not want to use the 30 days option. And then you will have to define Condition for Top 10.
    2. Top 10 users ( By no of queries executed )
    Use Query 0TCT_MCA1_Q0141.
    Similarly you have to modify this query.
    -Neelesh

  • Analytics for "top pages by visitor"

    Is there an analytics report for "top pages by visitor" or must we create a custom report for this?
    Example:
    Top Visitor ..................Page Url............................Number of Page Views
    Visitor A                       /sitepages/home.aspx         85
    Visitor B                      /sitepages/home.aspx          80
    Visitior A                     /sitepages/links.aspx            80
    Etc.

    Hi Aunt,
    Have you checked the following article with using SharePoint Flavored Weblog Reader tool?
    http://sharepoint.stackexchange.com/questions/60259/sharepoint-2013-usage-reports-where-are-the-details
    Thanks
    Daniel Yang
    TechNet Community Support

  • What is the Use For Top 3 Contributors

    Hi All,
    What is the Use For Top 3 Contributors in the Forums
    REgards
    Vamsi

    Hi,
    I think it is purely for information purposes. I do not think anything is actually done with the information as claimed by other posts.
    (Although some sort of recoginition in the form of a statue does seem a good idea and would encourage more posting if there was something to aim for)
    Kind regards
    Colin.

  • Query for top 10 selling products and their current stock

    Hi ppl
    I am using the sales overview cube 0SD_C03 to get top 10 selling products. What I want is to get the current stock available of the top 10 products from Material Stocks/Movements cube 0IC_C03. From what I know, we have to make a multiprovider to get this information. Can anyone guide me how to go about it?

    Hello Javed,
                         You can use Replacement path for this.
    1.Create a report for Top 10 Products in InfoCube 0SD_C03 - Exampls Report A
    2.Create another report with Stock and use a variable for Product with processing type replacement path in InfoCube0IC_C03 - Example Report B
    3. In Report B and assing the Report A to this variable.
    When you execute the Report B it will execute the Report A in background and displays it in Report B.
    Hope it helps,
    thanks
    Chandran

  • Oracle query for top two salary of each group departmentwise

    oracle query for top two salary departmentwise

    sigh...
    But anyway,
    Top-n queries:
    http://www.oracle.com/technology/oramag/oracle/07-jan/o17asktom.html
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:2853107469873
    and ofcourse lots of 'em here on OTN...

  • Tool Tip for Top Level Navigation - EP6SP2?

    Hi,
    Is it possible to provide tool tip for top level navigation.
    We have only one level TLN and Detail Navigation. On mouse over of TLN objects is it possible to provide tool tip?
    Thanks.

    Hi Raja,
    as Pankaj stated, the NavTagLib is the answer - but: it needs the LightFrameworkPage. And both together at the moment for example doesn't support Collaboration, means, if you click on some room, bang, error messages and nothing does work as expected.
    If you don't need CollRooms, you might give it a try.
    In addition, you can check out the "Hover effect", see http://help.sap.com/saphelp_nw04/helpdata/en/53/a16a3e54a2e946e10000000a114084/frameset.htm - it's probably not really what you want, I just want to point to that possibility (working within the standard framework page) for a complete overview.
    The last possibility is to modify com.sap.portal.navigation.toplevel; the TLN entries are rendered through toplevelnavigation.js, methods printLevel/printLevel1Table/printLevel2Table.
    Hope it helps
    Detlev

  • Top 20 (details) for top 20 (summary)

    I have a query whose structure is somewhat like:
    select distinct c,t, cu, s, somenumber, all
    from
    (-- outermost
        SELECT 
        t, c, cu,somenumber,all,c_cd, cname
        FROM ...
        where ...
        and c_cd in 
                       (--1st
                        select c_cd from
                            (--2nd
                            select c_cd, name,somenumber,ALL
                            from
                            (-- 3rd
                               SELECT c_cdc cname,
                               ...m,
                                sum(o) ALL
                                FROM
                                where
                                group by c_cd, cname
                                ORDER BY somenumber desc
                            )-- 3rd
    where rownum <=20
                            )-- 2nd
                            )-- 1st                    
    group by t,cu, c_cd, cname
    order by somenumber desc
    )-- outermost
    where rownum <=20 -- this wont return top 20 per c_cd because no group by. How can I get top 20 details (outer query) for top 20 summary c_cd's (summary inner query)
    order by somenumber desc what I am trying to do here is:
    the inner query returns 20 c_cd's. The outer (main) query returns to 20 details (by somenumber) for that 10 cd_s.
    However I am not able to say that give me the top 10 details for the give 20 c_cd's.
    It is like give me top 20 based on somenumber group by the given top 20 c_cd's.
    Any idea how can I modify my query and get the results?

    Is there some reason you can't accomplish what you want, far more easily, using analytic functions?
    http://tahiti.oracle.com
    http://asktom.oracle.com
    http://www.psoug.org/library.html

Maybe you are looking for