I have a table which has a recurring field. I need a function to count and say which recurrence is in nth line. i.e.;
If the table is as follows;
ID NAME CLASS
---------------
1 Tom a
2 Dick b
3 Harry c
4 Marry b
5 Bob c
6 Mat c
7 Mandi a
A function like COUNT(class) can count how many times each class value has been occurred. But I need a function to output a result like follows;
ID NAME CLASS (I_NEED) COUNT
--------------------------------
1 Tom a 1 2
2 Dick b 1 2
3 Harry c 1 3
4 Marry b 2 2
5 Bob c 2 3
6 Mat c 3 3
7 Mandi a 2 2
I am using SQL Server 2010R2
Any ideas will come in great help.. Thanks in advance!!
I think this is what you are looking for: