Specific number of rows within field(s)

I'd like to get Top-N of Amt within Name&Loc as shown below.
Is there a way to reset either COUNT or ROWNUM to get this result?
Name---Loc--(ROWNUM)--Amt
James--abc--------1--1000
James--abc--------2---900
James--abc--------3---750
James--def--------1---500
James--def--------2---300
Jill---abc--------1---400
Jill---abc--------2---150
Jack---xyz--------1--2000
Jack---xyz--------2--1800
Thank you in advance for your help.

try this,
select rownum as rank,ename,sal from ( select ename,sal from emp order by sal desc) where rownum<6
This query works on EMP table of SCOTT user.
If you change "desc" to "asc" it will start from lower to higher values. You can also play with the condition ( rownum < 6 ) to fetch ur desired no. of rows.
Hope this helps,
Kalpen.
<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Danielle:
Thanks for the reply, but that's not what I'm looking for.
Is there a way to get the Top-N (top 10,top20...)records within a group of fields (e.g. Name & Loc )?<HR></BLOCKQUOTE>
null

Similar Messages

  • Select  a specific  number of rows in query

    How can a specific number of rows be selected in a query? For example, a query retrieves 30,000 records and I want to retrieve the output by groups of 5,000. I want the query to retrieve the first 5,000 records, then the next 5,000 records etc. I tried rownum but that does not work.
    Thanks,
    PANY

    Not AGAIN. Please...........
    Do you know how to Google? Search forum?
    Why do you ask this boring FAQ AGAIN?
    Sybrand Bakker
    Senior Oracle DBA
    Experts: Those who know how to search.

  • Getting a specific number of rows

    Hi,
    I would like to know how to get a specific number of rows. For example, I want to page data in my web application, so I'd like to be able to retrieve just 25 rows in my SELECT statement. I searched and I couldn't see anything under the obvious keywords of LIMIT and TOP (as used by other database vendors) so I'm wondering if possible, what do I need to do - a pointer to the relevant documentation would be helpful also.

    You can achieve this with rownum
    http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/pseudocolumns009.htm#i1006297
    Best regards
    Maxim

  • Fitching a specific number of rows

    hi all
    i want to fitch a specific number of rows in my query
    not all matches (SQL2000 Server )
    what command in my sql query can be placed to do so
    thanks

    set rowcount n

  • Return specific number of rows depending on the data in a column in table

    Hi,
    I have a table named orders which has column orderid and noofbookstoorder in addition to other columns.
    I want to query the orders table and depending on the value of the 'noofbookstoorder' value return that number of rows.
    Eg
    Orderid noofbookstoorder
    1 1
    2 3
    3 2
    when I query the above data saying
    select * from orders where orderid=2;
    since it has noofbookstoorders value as 3 the query should return 3 rows and when I query
    select * from orders where orderid=3;
    it should return 2 rows and
    select * from orders where orderid=1;
    should return 1 row.
    Is it possible to achieve this. If yes, then how do I write my query.
    Thanks in advance.

    with t as (
               select 1 Orderid,1 noofbookstoorder from dual union all
               select 2,3 from dual union all
               select 3,2 from dual
    select  t.*
      from  t,
            table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.OdciNumberList))
      where Orderid = <order-id>
    /For example:
    SQL> with t as (
      2             select 1 Orderid,1 noofbookstoorder from dual union all
      3             select 2,3 from dual union all
      4             select 3,2 from dual
      5            )
      6  select  t.*
      7    from  t,
      8          table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.OdciNumberList))
      9    where Orderid = 2
    10  /
       ORDERID NOOFBOOKSTOORDER
             2                3
             2                3
             2                3
    SQL> with t as (
      2             select 1 Orderid,1 noofbookstoorder from dual union all
      3             select 2,3 from dual union all
      4             select 3,2 from dual
      5            )
      6  select  t.*
      7    from  t,
      8          table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.OdciNumberList))
      9    where Orderid = 3
    10  /
       ORDERID NOOFBOOKSTOORDER
             3                2
             3                2
    SQL> with t as (
      2             select 1 Orderid,1 noofbookstoorder from dual union all
      3             select 2,3 from dual union all
      4             select 3,2 from dual
      5            )
      6  select  t.*
      7    from  t,
      8          table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.Odc
    iNumberList))
      9    where Orderid = 1
    10  /
       ORDERID NOOFBOOKSTOORDER
             1                1
    SQL>  -- And if you want to select multiple orders
    SQL> with t as (
      2             select 1 Orderid,1 noofbookstoorder from dual union all
      3             select 2,3 from dual union all
      4             select 3,2 from dual
      5            )
      6  select  t.*
      7    from  t,
      8          table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.Odc
    iNumberList))
      9    where Orderid in (2,3)
    10  /
       ORDERID NOOFBOOKSTOORDER
             2                3
             2                3
             2                3
             3                2
             3                2
    SQL> SY.
    Edited by: Solomon Yakobson on Oct 26, 2009 7:36 AM

  • Select specific number of rows

    i'm listing all data entries in a database.
    for that i want to select the 1st ten entires, then the next ten and so on ordered
    by date_column.
    how can i do that? is it possible with rownum?
    in mysql/php i did it with limit
    $query = "select * from article where parent_id=0 order by date desc, time desc limit $select, 10";
    please email me.
    thanks for help
    chris

    but what about rownum if i want the
    records from 10-20?
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Chen Zhao ([email protected]):
    If you are using Oracle 8i, you can use ROWNUM to specify the specific number of records. You can see the ROWNUM by querying:
    SELECT *
    FROM (SELECT column_name FROM table_name ORDER BY column_name)
    WHERE ROWNUM<10
    CHEN<HR></BLOCKQUOTE>
    null

  • Setting a specific number of rows visiable in a JTable

    Hi there,
    I am implementing the Master-Detail pattern by using a using a JSplitPane to devide a JPanel into two.
    In the upper split-pane I show a JTable as the Master View.
    In the lower split-pane I show a JTable as the Detail View.
    My problem is that I just want to show 2 (two) rows and the Header in the Detail-View.
    The default behavier is that my SplitPane shows 1 and a half row and the tableHeader.
    How can I tell the SplitPane that I (only) want two rows and the Header ?

    table.setPreferredSize(...);Hi again,
    thanks for input !
    I tried your suggestion but it did not help me.
        int rowHeight = detailCompareTable.getRowHeight();       
        Dimension headerSize = detailCompareTable.getTableHeader().getPreferredSize();       
        d = new Dimension ((int) d.getWidth(), (int) (2 * rowHeight + headerSize.getHeight()));
        detailCompareTable.setPreferredSize(d);
       masterDetailSplitPane.resetToPreferredSizes();What am I gettig wrong ?

  • JTextArea - set specific amount of rows, or characters...

    I'm working on a Applet which handles text according to given parameters. One of these parameters sets a JTextArea to the horizontal size of, lets say: 5 rows. What i want is that once this TextArea is set to a specific number of rows no text beyond those rows can be inserted. 5 rows, or a specific amount of characters are allowed.
    My problem is that the TextArea wont stop allowing text vertically. The TextArea is visibly set to 5 rows, which doesnt change. But how can i stop text from being inserted beyond row 5?
    We have tried a number of different approaches, from trying to set TextArea's size with invisible scrollbars to overriding invalidate()...

    I never understand why people want to limit the number of rows in a JTextArea. Add the text area to a scroll pane and scroll bars will appear when the number of rows exceed the display area. The point of using a text area is to allow the user to enter data in a flexible format. If the format is not flexible then maybe you should be using another component or combination of combination of components.
    Setting a maximum character size is valid if you intend to store the data on a database with a fixed size field. It is easy to do this by using a custom Document with you JTextArea. Read this section from the Swing tutorial on "General Rules for Using Text Components" for example code on how to do this:
    http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html
    Note, if you really want to limit the text area to 5 lines then count the number of new line characters in the document and don't allow them to enter more than 4.

  • Need value in one field to populate various number of rows in a table

    I have a table created similarly to the sample Purchase Order form. I want the user to enter the quantity needed. Then I want to have a script populate the quantity field on each item in the table. However, some items that are ordered have a different number of parts. I'm not sure how to account for the various number of rows that may be encountered.
    Thanks,
    MDawn

    Hi,
    You can set the type to 'calculated - user can override' in the Object > Value palette. Example here: https://acrobat.com/#d=20TXqhWneiQhOMRVoJVXhQ
    However I am not sure if you will get the user experience that you are after. You can set the quantity rawValue to match that of the first row. The user would be able to override this, but will get warning messages, which may be disconcerting.
    Hope that helsp,
    Niall

  • Returning specific rows within a resultset.

    I have a table with the following rows:
    Category Site Title
    ======== ==== ======
    1 1 sometitle
    123 1 sometitle
    128 1 sometitle
    4 1 sometitle
    10 1 sometitle
    I have a REF cursor that looks like this:
    OPEN RefCursor FOR
    SELECT Category, Site, Title
    FROM TableName
    WHERE Site = 1
    ORDER BY Category;
    Now...Here is the catch. In that same select statement, I want to be able to retrieve a specific range of rows to return, once the 'order by' is done.
    I want to be able to execute my query, having it return rows 2 to 4...
    So my RefCursor should contain:
    Category Site Title
    ======== ==== ======
    4 1 sometitle
    10 1 sometitle
    123 1 sometitle
    The two important things are this:
    1- The initial resultset must be sorted first..THEN I want to select specific rows.
    2- The final result set MUST be a Ref Cursor.
    Anyone have suggestions?

    This will retrieve ordered rows 2 -4.
    (SELECT Category, Site, Title
    FROM
    (select category, site, title
    from tablename
    order by category)
    WHERE Rownum < 5)
    MINUS
    (SELECT Category, Site, Title
    FROM
    (select category, site, title
    from tablename
    order by category)
    WHERE Rownum < 2)
    /

  • How to Efficiently Sample a Fixed Number of Rows

    Good afternoon. I need to select a specific number of random rows from a table, and while I believe my logic is right it's taking too long, 30 minutes for a routine data size. Hopefully someone here can show me a more efficient query. I've seen the SAMPLE function, but it just randomly selects rows on a one-by-one basis, without a guaranteed total count.
    This is the idea:
    INSERT INTO Tmp_Table (Value, Sequence) SELECT Value FROM Perm_Table, DBMS_RANDOM.VALUE;
    SELECT Value FROM Tmp_Table WHERE ROWNUM <= 1234 ORDER BY Sequence;I'd need to put the ORDER BY in a subselect for ROWNUM to work correctly, but anyway that's just an illustration. My actual need is a little more complicated. I have many sets of data; each set has many rows; and for each set I need to return a specific (different) number of rows. Perhaps project A has three rows in this table, and I want to keep two of them; project B has two rows, and I want to keep one of them. So I need to identify, for each row, whether it's valid for that project. This is what my data looks like:
    Project Person  Sequence Position Keeper
    A       Bill    1234     1        Yes
    A       Fred    5678     3        No
    A       George  1927     2        Yes
    B       April   5784     2        No
    B       Janice  2691     1        YesI populate Sequence with random values, then calculate the position of each person within their project, and finally discard people who's Position is greater than Max_Targets for the Project. Fred and April have the highest random numbers, so they're cut. It's not the case that I'm just trimming one person from each project; the actual percentage kept will range from zero to 100.
    Populating the list with random values is not time-consuming, but calculating Position is. This is my code:
    UPDATE Tmp_Targets T1
    SET Position =
      SELECT
       COUNT(*)
      FROM
       Perm_Targets PT1
       INNER JOIN Perm_Targets PT2 ON PT1.Project = PT2.Project
       INNER JOIN Tmp_Targets T2 ON PT2.Target = T2.Target
      WHERE
           T1.Target = PT1.Target
       AND T2.Sequence <= T1.Sequence
      );The Target fields are PKs, and the Project and Sequence fields are indexed. Is there a better way to approach this? I could write a cursor that pulls out project codes and performs the above operations for each project in turn; that would be logically simpler and possibly faster. Has anyone here addressed a similar problem before? I'd appreciate any ideas.
    This is on 9.2, in case it matters. Thank you,
    Jonathan

    You've not given any indication of how max targets for a given project is determined, so for my example I'm using the ceiling of 1/2 of the number of records in each project which gives the same number of yes and no responses per project as you had:
    with dta as (
      select 'A' project, 'Bill' person from dual union all
      select 'A', 'Fred' from dual union all
      select 'A', 'George' from dual union all
      select 'B', 'April' from dual union all
      select 'B', 'Janice' from dual
    ), t1 as (
      select project
           , person
           , row_number() over (partition by project order by dbms_random.value) ord
           , count(*) over (partition by project) cnt
           , rownum rn
        from dta
    select project
         , person
         , ord
         , cnt
         , case when ord <= ceil(cnt/2) then 'Yes' else 'No' end keep
      from t1
      order by rn
    PROJECT PERSON ORD                    CNT                    KEEP
    A       Bill   2                      3                      Yes 
    A       Fred   3                      3                      No  
    A       George 1                      3                      Yes 
    B       April  1                      2                      Yes 
    B       Janice 2                      2                      No  
    5 rows selectedIn this example I use an analytic function to assign a random ordering for each record within a project in the middle query, in the final output query I am determining the yes no status based on the order within a project and the count of records in the project. If you had a table of projects indicating the thresh hold you could join to that and use the thresh hold in place of the ceil(cnt/2) portion of my inequality in the case statement.

  • Restrict number of rows to be pulled from PeopleSoft's PS_LEDGER table while importing data in FDMEE

    Hi,
    We need to know if FDMEE 11.1.2.3.520 product supports restricting number of rows to be pulled from PeopleSoft's PS_LEDGER table.
    All the records fetched from PS_LEDGER is getting loaded into TDATASEG table.
    Currently, it is trying to pull all the records based on the given "period", "version" and "year" combination. We are looking to restrict rows based on specific account/entity/program/subprogram combination.
    If this is can be done, will it be an out-of-the-box functionality or does it require any customization/import scripts/api.
    Admin guide does say we can use Jython to filter rows using import scripts. However, it seems to be limited to file not a table as a source.
    I have attached a document with the screenshots so that the issue is better understood !
    Thanks,
    Hari

    1)
    When you set a column to hidden in a classic report using the method I described, it creates hidden form elements for that column.
    <tt><input type="hidden" name="f01" value="" id="f01_0002"></tt>
    You should inspect the source to figure out the name value.
    Since this belongs to the wwv_flow form, we can therefore get this data with: wwv_flow.f01
    Alternatively, you could have used the apex_item API to achieve the same result, which probably gives a bit better control.
    http://docs.oracle.com/cd/E37097_01/doc/doc.42/e35127/apex_item.htm#CHDBFHGA
    select apex_item.hidden(1, col) || col col
    from table
    Set that column to a standard report column so it doesn't escape the html.
    You can also reference the data in these fields using PL/SQL using the apex_application API:
    http://docs.oracle.com/cd/E37097_01/doc/doc.42/e35127/apex_app.htm#CHDGJBAB
    2)
    As above, setting the column to hidden creates hidden elements on the page. It is simply f01 because that is the only hidden field I would have on my page. With four reports on the page, you would need to be careful not to do the same on the other reports, as you would get inaccurate data. For each report, setting columns to hidden always starts with f01. In that, you would be best to use the apex_item API.
    I actually initially ran into this issue when i had a tabular form on the same page as a report with hidden fields, which was causing conflicts in the page processes.
    Hope it helps.

  • Number of Rows Displayed in a SQL Report Region

    Hi,
    Just wondering whether it is possible to control the 'Number of Rows' displayed under the 'Layout and Pagination' section within the Report Attributes page.
    Basically need to know if I can programmatically control this or even better, can it be customized by the user as the user may want to see say 15 rows, 200 rows or 'All' rows of a certain region on the page. FYI, I have three different report regions on one page and want to give the user the flexibility to modify the number of rows displayed per region.
    Thanks.
    Tony.

    Tony,
    you can find that in this how-to document:
    http://www.oracle.com/technology/products/database/htmldb/howtos/howto_report_rownum.html
    Denes Kubicek

  • How to limit the number of rows in a report

    I have several reports with a number of parameters - date ranges etc.
    Depending on the parameter values selected by the user the reports can return thousands of rows.
    I would like to limit the number of rows returned to, say, 500. If more than 500 rows are returned by the query then display an error message requesting that the user enter more specific parameters.
    Ideally for performance reasons it would be good to catch the error before the datafile is generated, but I don't know if this is possible. Alternatively a check in the template might do the job - using COUNT on the group?.

    Hi Hugh,
    In your query, you got to add rowum < 500 or some sort of DB specific limit to the row being returned,
    this will help to stop the report to get more than 500 records and the report template wont have any restriction.
    or
    you can do that in template too, but i would not recommend.
    In these both cases or in any case, you cannot give any meaningful error if it exceeds N rows,there is no option like this till now.

  • Different number of rows for different columns in JTable

    hi
    I need to create a JTable with different number of rows for different columns...
    Also the rowheight should be different in each column...
    say there is a JTable with 2 columns... Col1 having 5 rows and column 2 having 2 rows...
    The rowHeight in Col2 should be an integer multiple of Rowheight in Col1
    how do I do this ??
    can anybody send me some sample code ?????
    thanx in advance

    How about nesting JTables with 1 row and many columns in a JTable with 1 column and many rows.
    Or you could leave the extra columns null/blank.
    You could use a GridBagLayout and put a panel in each group of cells and not use JTable at all.
    It would help if you were more specific about how you wanted it to appear and behave.

Maybe you are looking for

  • Iphone 5 screen won't rotate how do I fix this ?

    My screen doesn't rotate there is a little padlock next to the battery life can anyone please help

  • LR4.1 doesn´t create a psd

    when i use the external editor function, LR4.1 doesn´t create a psd-file. CS5 will directly open the DNG. With LR4.0 i didn´t have this problem. Anyone here to solve this problem? (VISTA Ultimate)

  • WAD export web table to BSP application

    Hi all, I need to extract value from a wad table and after insert them to a table in a bsp page. I've first create a table on a wad page ,i've apply a check box filter then the problem for sent filtered date to a bsp page. it's possible? may i do tha

  • Problematic frame: # V  [jvm.dll+0x51d46]

    I keep repeatably get this error. I changed my paths, system restored back to normal paths, reinstalled many many times, i dont know what else to do. If anyone knows what i can do to get this working i would appreciate it. # A fatal error has been de

  • Syncing bookmarks via iCloud

    The sync of my Safari bookmarks via iCloud just doesn't work properly. I have an iMac and a MacBook Pro and I sync the bookmarks between the two devices. Sometimes, it works almost instinstantaneously, but now it has stopped working alltogether. What