大家好,我想用一个旧的数据表,取出其中的几个字段建造一个新数据表,这个新数据表中还有一些新添加的字段,请问大家用sql语句可以完成这个功能吗?
比如我有一个旧表:oldtable有以下字段
id、amt、 date、store、infee、outfee……
现在我想取其中几个有用的字段组成一个新表:newtable,newtable 包括以下字段
id、amt、 date、Importdate
其中id amt date 是元数据表中的值,而ImportDate是导入新表的时间,请问大家这个sql语句该怎么写啊?

解决方案 »

  1.   

    create table newtable as 
    select ot.id,ot.amt,ot.date,sysdate as importdate from oldtable;
      

  2.   

    create table newtable as 
    select ot.id,ot.amt,ot.date,sysdate as importdate from oldtable ot;
      

  3.   

    可以按楼上的方法建表,再添加时间字段,再插入时间。但这样会导致一个问题:importdate并不准确
    可以先建表
    create table newtable(id number,amt number, "date" date,Importdate date);
    insert into newtable
      select id,amt,"date",sysdate from oldtable;
      

  4.   

    我想像狂浪说得那样先新建一个表,然后再把另一张表中的字段插入到这张表中,可是我按照狂浪写的哪个sql语句插不进去啊,大家帮帮忙,看这个sql语句该怎么写啊,要能插入的,谢谢大家了
      

  5.   


      create table a  as select * from test t where 1=2;
       如果你不向要数据 加上这个条件
    想要 就加上WHERE 
       你要指定字段 则把 * 改成你要的字段
      

  6.   

    搞反了 你不向要数据 加WHERE  不向要去了WHERE