Consider a student table with 104 rows in it. I need to create groups with a minimum of 10 students in each groups. In the case with 104 students, I would end up having 10 groups of 10 students and 1 group of 4 students if I iterate on each students and create the grouping. There’s a rule that a group with remaining students cannot have less than 5 students in it (in this case the last group consist of 4 student). Two possible approach I’m trying to do:
- Roll up the last group that has less than 5 students and assign each of them to any groups, or
- Spread the last group evenly to any groups.
How do I achieve any of these? Many thanks.
Eric
You can use ntile.
Some sample code:
Try it out on SE-Data.