|
|
Posted on
2008-06-13 15:33
AmyQiu
阅读( 239)
评论()
收藏
举报
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)/3) from
(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,2) and exam_number<=a.exam_number)
group by substring(exam_number,7,2)) b )
from examinees a

|