M
Miriana
Guest
I have a table with 85224 rows. There are 89 distinct codes in the table. My challenge is:
Perform 3 NTH selects on this table to have the final result of:
25,000
25,000
25,000
Remaining 10,224
My problem here is that I have to take approximately the same number of rows per code and quantities per code can vary: for example code 228 has one row, code 114 has 7909 rows.
The only business rule is if there is one row per code it should go to first group of 25000 if there are 3 rows per code one should go to each of the 25,000 groups. I tried to resolve this with SQL cursor, but without success. SEQN is unique, ID is not.
The idea is to reach nth select of 25000 first, then second and third and at the end put the remaining records into the fourth group of 10224 keeping in mind that quantity of each code should be represented equally between the nth selects.
Sample of data
SEQN Code ID
1 214 100489
2 214 100622
3 415 1006842
4 414 1007003
5 416 1007018
6 214 1007126
Any help would be much appreciated.
Thank you everyone.
M.
Perform 3 NTH selects on this table to have the final result of:
25,000
25,000
25,000
Remaining 10,224
My problem here is that I have to take approximately the same number of rows per code and quantities per code can vary: for example code 228 has one row, code 114 has 7909 rows.
The only business rule is if there is one row per code it should go to first group of 25000 if there are 3 rows per code one should go to each of the 25,000 groups. I tried to resolve this with SQL cursor, but without success. SEQN is unique, ID is not.
The idea is to reach nth select of 25000 first, then second and third and at the end put the remaining records into the fourth group of 10224 keeping in mind that quantity of each code should be represented equally between the nth selects.
Sample of data
SEQN Code ID
1 214 100489
2 214 100622
3 415 1006842
4 414 1007003
5 416 1007018
6 214 1007126
Any help would be much appreciated.
Thank you everyone.
M.