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

Thread: Querying the occurence of rows without group by

  1. #1
    Join Date
    Nov 2003
    Posts
    4

    Querying the occurence of rows without group by

    Hi,

    I am wondering if the following is possible in an SQL Query:

    Consider the following Table

    TABLE1 =

    ID NAME
    --- ----
    102 JOEL
    256 MARK
    269 MARK
    270 JOSH
    369 AMY
    699 AMY


    SELECT NAME, occurence
    FROM TABLE1

    The result would be

    NAME occurence
    ---- ---------
    JOEL 1
    MARK 1
    MARK 2
    JOSH 1
    AMY 1
    AMY 2

    Cheers,
    M.

  2. #2
    Join Date
    Dec 2000
    Location
    Ljubljana, Slovenia
    Posts
    4,439
    Code:
    select 
      name,
      row_number() over
       (partition by deptno order by id) as occurence
    from table1;
    Jurij Modic
    ASCII a stupid question, get a stupid ANSI
    24 hours in a day .... 24 beer in a case .... coincidence?

  3. #3
    Join Date
    Nov 2003
    Posts
    4

    Thumbs up THX!

    Absolutely fantastic, thanks

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