Showing posts with label ROW_NUMBER(). Show all posts
Showing posts with label ROW_NUMBER(). Show all posts

Sequence number within a group

Saturday, 10 April 2010

The following query can be used to generate the sequence numbers within a group.

select 
 GROUP_ID
, GROUP_COUNTER= ROW_NUMBER()
                                      OVER (  PARTITION BY [GROUP_ID]
                                                    ORDER BY [GROUP_ID]
                                                   ) 
from GROUP_TABLE

This query can generate a output like the following.

GROUP_ID       GROUP_COUNTER
-------------------------------------------
AAA                   1
AAA                   2
AAA                   3
BBB                    1
BBB                    2
CCC                   1


An interesting article - Selecting Duplicate Rows in a table

Sunday, 18 October 2009

Hi All, we are back after a pause.Here's an interesting article which talks about the different ways of selecting the duplicate rows from a table.Hope it will be useful to you.


Article