Here is a sample table that mimics my scenario:
COL_1 COL_2
1 a
2 a
9 b
8 b
11 b
I have two columns where Column 1 have different numerical values and Column 2 represents different classes (a, b, c, etc.). In column 3 I would like to have them counted per class and matched with 0/1 numbers based on what was the biggest/lowest value in Column 1. So if in my example class “a” have only two values (in our example 1 and 2) they should be counted from 0 to 1 (where 0 stands for lowest number and 1 for biggest from Column 1). If class b is being represented by 3 entries I would like to have them matched by 0/1/2 numbers based on what is the biggest/lowest number from Column 1 in “b” class.
After my query I woul like to have something like this:
COL_1 COL_2 COL_3
1 a 0
2 a 1
9 b 1
8 b 0
11 b 2
So, in other words I want a query that looks how many duplicates we have in column 2 and gives them values from lowest to biggest (where 0 is lowest) based on what they are represented in column 1.
Thanks to anyone who helps me with this.
*I am using MS SQL, if that would make any difference.
1 Answer