有2个表,t1,t2,我想从t2中查找col1和col2的数据插入到t1对应的两列中,但还要同时插入几个固定的数值也就是 t1中有5列,从t2中只查询2列,其余的三列用固定的数据

解决方案 »

  1.   

    insert into t1
    select t2.a,t2.b,1,2,'aaa' from t2
      

  2.   


    insert t1 select @val1,@val2,@val3,col1,col2 from t2  --位置自己定 
      

  3.   

    insert into t1 
    select t2.cola,t2.colb,1,2,3 from t2
      

  4.   

    insert into t1
    select t2.a,t2.b,1,2,'aaa' from t2
      

  5.   

    insert into t1
    select col1,col2,固定数据1,固定数据2,固定数据3 from t1
      

  6.   

    insert into t1(col1,col2,col3,col4,col5)
    select col1,col2,'固定数值1' as col3,'固定数值2' as col4,'固定数值3' as col5 from t2
      

  7.   


    select col1,col2,col3='固定值3',col4='固定值4',col5='固定值5' into t2 from t1试看
      

  8.   

    insert into table1(col1,col2) select col3,col4 from table2