------解决方案-------------------- select case when isnull(COUNT(*),0)=5 then 组号+1 else 组号 end from tab
where 组号=(select max(组号) from tab)
group by 组号 ------解决方案-------------------- 是这样吗:
create table tb(id int identity(1,1),v varchar(10))
go
insert into tb
values('a')
go 21
select *,
'group'+ cast((id-1) / 5 as varchar) 'group'
from tb
/*
id v group
1 a group0
2 a group0
3 a group0
4 a group0
5 a group0
6 a group1
7 a group1
8 a group1
9 a group1
10 a group1
11 a group2
12 a group2
13 a group2
14 a group2
15 a group2
16 a group3
17 a group3
18 a group3
19 a group3
20 a group3
21 a group4
*/