日期:2014-05-18  浏览次数:20554 次

循环的语句????
 
 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 @bill
select 1,'sfs','32' union all
select 2,'a','13' union all
select 3,'s','32' union all
select 4,'d','3a' union all
select 9,'f','3q'

select distinct d=(select count(1)/3+1 from @bill where a<b.a)
into #billnew
from @bill b
order by d

select * from #billnew

d
-----------
1
2

(2 行受影响)

------解决方案--------------------
up