读书人

循环的语句?该如何解决

发布时间: 2012-03-14 12:01:12 作者: rapoo

循环的语句????

bill表:
a b c 列
1 sfs 3
3 dff 3
3 dfs df
4 rrr ww

从bill表取数字,生成另一个表,bill表假如有20行,20/3 生成的新表billnew 就有7行,同时新表类似这样

billnew结构是:d列按顺序的流水号,
d
1
2
3


如何写呢????







[解决办法]

SQL code
declare @bill table(a int,b nvarchar(20),c nvarchar(20))insert @billselect 1,'sfs','32' union allselect 2,'a','13' union allselect 3,'s','32' union allselect 4,'d','3a' union allselect 9,'f','3q'select distinct d=(select count(1)/3+1 from @bill where a<b.a)into #billnewfrom @bill border by dselect * from #billnewd-----------12(2 行受影响)
[解决办法]
up

读书人网 >SQL Server

热点推荐