有表:
    name       fenshu        
    张三          89
    李四          92
    王五          79
现想插入一列,变为:
    name       fenshu     age
    张三           89       18
    李四           92       17
    王五           79       17
插入的这一列可以通过select语句从另外的表中得到,
本人刚学sql语句,只知道insert是插入行,不知道怎样插入列,
请各位不吝赐教!
    

解决方案 »

  1.   


    update 表1 set age=(select age from 表2 where 表1.字段1=表2.字段1)
    where exists(select 1 from 表2 where 表1.字段1=表2.字段1)
      

  2.   

    插入一列:ALTER table_name ADD(age number(5));
    然后再插入数据:update table_name set age=18 where name='张三';
                  update table_name set age=17 where name='李四';
                  update table_name set age=17 where name='王五';
      

  3.   

    或者删了从来
    drop table 表1 
    create table 表1 as select col1,col2,col3 from 表2 where ... 
      

  4.   


    表2里只有age这个字段,没有前两列,所以上面的好像不行
      

  5.   

    先修改表1,新增列age,然後再從別的表更新表1. 列是沒辦法新增的。update 表1 set age=(select age from 表2 where 表1.字段1=表2.字段1)
      

  6.   

    插入一列:ALTER table_name ADD(age number(5));update 表1 set age=(select age from 表2 where 表1.字段1=表2.字段1) 
      

  7.   

    其实没必要那么复杂,方法很多,比如:
    create view v_name as select a.name,a.fenshu,b.age from table_1 a,table_b where 
    或者把view改成table,然后把原来的table删掉,把现在的v_name 改名成原来的table就可以了
      

  8.   


    alter talbe tableName add age number(3);
      

  9.   

    估计还是得分修改表结构和修改表数据两步走,没有类似insert插入行这样的插入列的语句吧。
      

  10.   

    1.新增加一列age
    2.update table1 set age=(select ......)
      

  11.   


    update 目标表 a 
    set age = (select age from 源表 b where a.字段=b.字段)
    where exists (select 1 from 源表 b where a.字段=b.字段)
      

  12.   


    update table a
    set age=(select age from table b where a.字段=b.字段)
    where exists (select 1 from table b where a.字段=b.字段)