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 这样的语句
     谢谢。 

解决方案 »

  1.   

    问题1.如果表有上万条记录,按你显示结果,将生成上万列的表了,没什么意思!!!!问题2. Select * into Table3 from (select a.numA,b.NumB from Table1 a,table2 b) kk要求Table3在数据库中不存,Select * into 语句会自动创建Table3
    至于括号内的select查询,Table1和table2要什么连接条件,自己处理了
      

  2.   

    哦,补充一下第一个问题吧,谢谢各位帮助1:  
      表 
      Num  type  
       1    1 
       11   1 
       111  1 
       2    2 
       22   2 
       222  2按照 type的值进行分成两个字段
     
     显示为  
      NumA  NumB  ---字段名随便起都可以 
      1       2 
      11      2 
      111     222 
      必须在一条SQL里实现。 
      

  3.   

    第一个用联接,第二个用UNION,因为条件不清楚,给不出语句。
      

  4.   


    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 行)*/
      

  5.   

    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*(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 行)
    */
      

  6.   


    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 
      

  7.   

    先把Type为1的对应的Num值写成一个字段,再把Type为2的写成一个字段。为什么要写成
    1    2
    11   22
    111  222是按照他们在表中的顺序排列的 
    1是 Type为1的第一条记录 11是Type为1的第2条,111是第三条
    2是 Type为2的第一条记录 22是Type为2的第2条,222是第三条这个值是我随便给的,不是实际值,实际值是没有任何规律的浮点数。
      

  8.   

    那Type为1的有3条
    type为2的有4条 
    结果集中第四条应该是怎样的