SQLTeam.com | Weblogs | Forums

Add Row count within a group


#1

Hello,

How to add the row number group by the StudentId?

Here is my select statement;

Select StudentId,ClassType
From Tblstudent

Output:
StudentId ClassType
DD2456 A
DD2456 V
DD2456 B
FGR123 E
FGR123 R
FRT557 S
FRT557 T
FRT557 C
FRT557 A

Output I want:
Row StudentId ClassType
1 DD2456 A
2 DD2456 V
3 DD2456 B
1 FGR123 E
2 FGR123 R
1 FRT557 S
2 FRT557 T
3 FRT557 C
4 FRT557 A


#2

Is this some type of homework / class assignment?

I think maybe it is, so I can't give you the full answer. But I can give you a big hint -- try ROW_NUMBER() with partitioning.


#3

Hi ScottPletcher,

No, this is just for my testing purposes but you are correct, I used Row_number and I got it...Thanks scott