当前位置: 代码迷 >> Sql Server >> 请教怎么执行代码把表TB1数据按照倍投数的多少重复显示得到表TB2
  详细解决方案

请教怎么执行代码把表TB1数据按照倍投数的多少重复显示得到表TB2

热度:24   发布时间:2016-04-24 10:39:18.0
请问如何执行代码把表TB1数据按照倍投数的多少重复显示得到表TB2
--> 测试数据[TB1]
if object_id('[TB1]') is not null drop table [TB1]
go 
create table [TB1]([notext] nvarchar(20),[blu] nvarchar(2),[倍投数] int)
insert [TB1]

select '01 06 08 13 20 28','10',4  union all
select '13 22 26 27 28 29','16',7  union all
select '05 09 11 19 27 33','11',1 


请问如何执行代码把表TB1数据按照倍投数的多少重复显示得到表TB2

表TB2		
notext blu 倍投数
05 09 11 19 27 33 11 1
02 05 09 23 29 33 13 4
02 05 09 23 29 33 13 4
02 05 09 23 29 33 13 4
02 05 09 23 29 33 13 4
01 06 08 13 20 28 10 4
01 06 08 13 20 28 10 4
01 06 08 13 20 28 10 4
01 06 08 13 20 28 10 4
13 22 26 27 28 29 16 7
13 22 26 27 28 29 16 7
13 22 26 27 28 29 16 7
13 22 26 27 28 29 16 7
13 22 26 27 28 29 16 7
13 22 26 27 28 29 16 7
13 22 26 27 28 29 16 7


图示说明如下

------解决方案--------------------
试试这个:


if object_id('[TB1]') is not null drop table [TB1]
go 
create table [TB1]([notext] nvarchar(20),[blu] nvarchar(2),[倍投数] int)
insert [TB1]

select '01 06 08 13 20 28','10',4  union all
select '13 22 26 27 28 29','16',7  union all
select '05 09 11 19 27 33','11',1  union all
select '02 05 09 23 29 33','13',4
go


--补足记录
select notext,blu,[倍投数]
from [TB1] t,master..spt_values s
where s.type = 'P' and s.number >=1 and s.number <= [倍投数]
order by [倍投数]
/*
notext blu 倍投数
05 09 11 19 27 33 11 1
02 05 09 23 29 33 13 4
02 05 09 23 29 33 13 4
02 05 09 23 29 33 13 4
02 05 09 23 29 33 13 4
01 06 08 13 20 28 10 4
01 06 08 13 20 28 10 4
01 06 08 13 20 28 10 4
01 06 08 13 20 28 10 4
13 22 26 27 28 29 16 7
13 22 26 27 28 29 16 7
13 22 26 27 28 29 16 7
13 22 26 27 28 29 16 7
13 22 26 27 28 29 16 7
13 22 26 27 28 29 16 7
13 22 26 27 28 29 16 7
*/
  相关解决方案