水滴石穿

渴望成为高手--Amy.Qiu
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

接规则,每三个一组编一个号

Posted on 2008-06-13 15:33  AmyQiu  阅读(225)  评论(0编辑  收藏  举报

 

create table #examinees(exam_number varchar(16), room int)
insert #examinees(exam_number) 
select '100100010001'
union all select '100100010002' 
union all select '100100010003' 
union all select '100100010004' 

union all select '100100020001' 
union all select '100100020002' 
union all select '100100020003' 
union all select '100100020004'
union all select '100100020005' 

union all select '100100040001'
union all select '100100050001'

union all select '100100060001' 
union all select '100100060002' 
union all select '100100060003' 
union all select '100100060004' 
union all select '100100060005' 
union all select '100100060006' 

select * from #examinees

update a set room = (select sum((rs+2)/3from 
        (
select rs=count(*from examinees 
               
where substring(exam_number,7,2)<substring(a.exam_number,7,2
               
or (substring(exam_number,7,2)=substring(a.exam_number,7,2and exam_number<=a.exam_number)
               
group  by substring(exam_number,7,2)) b )
from examinees a