表每固定条分组显示

来源:互联网 发布:上海大型图书馆知乎 编辑:程序博客网 时间:2024/05/03 22:11

create table #t(nm varchar(2))

insert into #t(nm)
(
select 'aa' union
select 'bb' union
select 'cc' union
select 'dd' union
select 'ee' union
select 'ff' union
select 'bg' union
select 'hh'
)

create table #t1(id int identity,nm varchar(2),num int)
insert into #t1(nm) select nm from #t

update #t1 set num=case when id=id/3*3 then id/3 else id/3+1 end
select * from #t1 

原创粉丝点击