sql2000如何每5行数据产生一个组号.
sql2000如何每5行数据产生一个组号.
数据包含一个自增列,即id从1开始自增,要求每5行增加一个组号,
即id从1到为5为group1,id从6到10为group2,11到15为group3...............
[解决办法]
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
/*
idvgroup
1agroup0
2agroup0
3agroup0
4agroup0
5agroup0
6agroup1
7agroup1
8agroup1
9agroup1
10agroup1
11agroup2
12agroup2
13agroup2
14agroup2
15agroup2
16agroup3
17agroup3
18agroup3
19agroup3
20agroup3
21agroup4
*/