Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Row Number by group

Author  Topic 

sg2255551
Constraint Violating Yak Guru

274 Posts

Posted - 2010-02-27 : 21:36:29
hi

How do i get row number using group by? for example, i have 2 groups (grpA, grpB) and in group A i have 5 rows and group B i have 8 rows.

I would like to display the row number for each group. Thanks

Group A
1
2
3
4
5
Group B
1
2
3
4
5
6
7
8

sg2255551
Constraint Violating Yak Guru

274 Posts

Posted - 2010-02-27 : 22:03:20
i have found the answer:

row_number() over (partition by Cust_ID order by Stores) as ROW_NUMBER

Thanks
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-01 : 01:58:27
Also refer this
http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -