22,209
社区成员
发帖
与我相关
我的任务
分享
select a1,a2,ceiling(a1/5.) as rn
from [表A]
-- 参考一下这个写法,效率可能会差点。。
select top 16 id , cast(name as varchar(10)) name into test
from sysobjects
order by id
go
select id , name , (select COUNT(*) from test x where test.id > id ) / 5 + 1 as newcol
from test
go
drop table test
go
(16 行受影响)
id name newcol
----------- ---------- -----------
3 sysrscols 1
5 sysrowsets 1
7 sysallocun 1
8 sysfiles1 1
17 syspriorit 1
19 sysfgfrag 2
23 sysphfg 2
24 sysprufile 2
25 sysftinds 2
27 sysowners 2
29 sysprivs 3
34 sysschobjs 3
41 syscolpars 3
44 sysnsobjs 3
46 syscerts 3
49 sysxprops 4
(16 行受影响)