下例没有普遍性,因为你给的数据太少,这样就够了: insert into table1 values ( select top 1 * from table2, select top 1 * from table2 where table2.字段 not in(select top 1 * from table2), select top 1 * from table2 where table2.字段 not in(select top 2 * from table2) )
TRY: select identity(int,1,1)num,* into #temp from table1 select identity(int,1,1)id,filename into #col1 from #temp where num%3=1 select identity(int,1,1)id,filename into #col2 from #temp where num%3=2 select identity(int,1,1)id,filename into #col3 from #temp where num%3=0insert into table2 select a.filename,b.filename,c.filename from #col1 a,#col2 b ,#col3 c where a.id=b.id and b.id=c.id
insert into table1 values
(
select top 1 * from table2,
select top 1 * from table2 where table2.字段 not in(select top 1 * from table2),
select top 1 * from table2 where table2.字段 not in(select top 2 * from table2)
)
将table2
filename
1
2
3
转换为
table1
file1 file2 file3
1 2 3
select identity(int,1,1)num,* into #temp from table1
select identity(int,1,1)id,filename into #col1 from #temp where num%3=1
select identity(int,1,1)id,filename into #col2 from #temp where num%3=2
select identity(int,1,1)id,filename into #col3 from #temp where num%3=0insert into table2
select a.filename,b.filename,c.filename from #col1 a,#col2 b ,#col3 c where
a.id=b.id and b.id=c.id
谢谢,trying.