1:
表
Num type
1 1
11 1
111 1
2 2
22 2
222 2
显示为
NumA NumB ---字段名随便起都可以
1 2
11 2
111 222
必须在一条SQL里实现。2
表
select numA From Table1
Select NumB From table2
这是查出来的两个字段
有一长表 Table3
NumA int
NumB int
怎么把直接插进去 用类似 Select into 这样的语句
谢谢。
表
Num type
1 1
11 1
111 1
2 2
22 2
222 2
显示为
NumA NumB ---字段名随便起都可以
1 2
11 2
111 222
必须在一条SQL里实现。2
表
select numA From Table1
Select NumB From table2
这是查出来的两个字段
有一长表 Table3
NumA int
NumB int
怎么把直接插进去 用类似 Select into 这样的语句
谢谢。
至于括号内的select查询,Table1和table2要什么连接条件,自己处理了
表
Num type
1 1
11 1
111 1
2 2
22 2
222 2按照 type的值进行分成两个字段
显示为
NumA NumB ---字段名随便起都可以
1 2
11 2
111 222
必须在一条SQL里实现。
declare @t table
(num int ,type int)
insert into @t select 1,1
insert into @t select 11,1
insert into @t select 111,1
insert into @t select 2,2
insert into @t select 22,2
insert into @t select 222,2select t.*,tt.* from @t t inner join @t tt on t.type*2=tt.type and len(t.num)=len(tt.num)
/*
1 1 2 2
11 1 22 2
111 1 222 2(所影响的行数为 3 行)*/
(num int ,type int)
insert into @t select 1,1
insert into @t select 11,1
insert into @t select 111,1
insert into @t select 2,2
insert into @t select 22,2
insert into @t select 222,2select t.*,tt.* from @t t inner join @t tt on t.type*(select top 1 type from @t group by type order by type desc )=tt.type and len(t.num)=len(tt.num)
/*
1 1 2 2
11 1 22 2
111 1 222 2(所影响的行数为 3 行)
*/
declare @t table
(num int ,type int)
insert into @t select 1,1
insert into @t select 11,1
insert into @t select 111,1
insert into @t select 2,2
insert into @t select 22,2
insert into @t select 222,2select num, (select top 1 num from @t where len(num)=len(num) and 2 * num=t.num ) ss from @t t where
(select top 1 num from @t where len(num)=len(num) and 2 * num=t.num ) is not null
1 2
11 22
111 222是按照他们在表中的顺序排列的
1是 Type为1的第一条记录 11是Type为1的第2条,111是第三条
2是 Type为2的第一条记录 22是Type为2的第2条,222是第三条这个值是我随便给的,不是实际值,实际值是没有任何规律的浮点数。
type为2的有4条
结果集中第四条应该是怎样的