当前位置: 代码迷 >> Sql Server >> 循环的语句?该如何解决
  详细解决方案

循环的语句?该如何解决

热度:4   发布时间:2016-04-27 14:26:36.0
循环的语句????
 
 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
  相关解决方案