DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: SQL Help

  1. #1
    Join Date
    Jun 2000
    Location
    chennai,tamil nadu,india
    Posts
    159

    SQL Help

    I have a Table for example
    Table X
    person varchar2(10),month varchar2(2),count number

    I want to select top 3 persons from the table for all the month.It should look like this

    person month count
    xxx jan 25
    yyy jan 20
    zzz jan 15
    aaa feb 30
    bbb feb 25
    ccc feb 10

    Pls. help me.

  2. #2
    Join Date
    May 2000
    Location
    ATLANTA, GA, USA
    Posts
    3,135
    Try this:

    SELECT PERSON, MONTH, COUNT
    FROM ( SELECT
    PERSON,
    MONTH,
    COUNT,
    ROW_NUMBER() OVER (PARTITION BY MONTH ORDER BY COUNT DESC) RN
    FROM TABLEA
    )
    WHERE RN <= 3
    ORDER BY 2,1 ;

    Tamil

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width