Puoi utilizzare ntile .
Alcuni esempi di codice:
declare @NumberOfStudents int
declare @StudentsPerGroup int
set @StudentsPerGroup = 10
set @NumberOfStudents = 104
select StudentID,
ntile(@NumberOfStudents / @StudentsPerGroup) over(order by StudentID) as GroupID
from Students
Provalo su SE-Data .