Мы можем сгруппировать данные в сегменты по 10, как показано ниже:
declare @table table(id int, name varchar(10))
INSERT INTO @table values
(1 ,'abc'),
(1 ,'xyz'),
(2 ,'abc'),
(2 ,'xyz'),
(2 ,'pqr'),
(3 ,'abc'),
(3 ,'xyz'),
(3 ,'pqr'),
(3 ,'mno'),
(3 ,'stu'),
(3 ,'def');
DECLARE @Tengroups int = (SELECT COUNT(*)/10 FROM @table)
--select @Tengroups, @RemainderTenGroups
select ID, NAME, NTILE(@Tengroups) over (order by rnk) as bucket from
(SELECT ID,NAME, row_number() over(order by id) as rnk FROM @table) as t
where rnk <= @tengroups * 10
-- remaining data, which was not in groups of 10 buckets. It will be new bucket
UNION ALL
select ID, NAME, @Tengroups + 1 as bucket from
(SELECT ID,NAME, row_number() over(order by id) as rnk FROM @table) as t
where rnk > @tengroups * 10
+----+------+--------+
| ID | NAME | bucket |
+----+------+--------+
| 1 | abc | 1 |
| 1 | xyz | 1 |
| 2 | abc | 1 |
| 2 | xyz | 1 |
| 2 | pqr | 1 |
| 3 | abc | 1 |
| 3 | xyz | 1 |
| 3 | pqr | 1 |
| 3 | mno | 1 |
| 3 | stu | 1 |
| 3 | def | 2 |
+----+------+--------+