SQL 如何从一张表中导出部分数据并建立一张新表

如题所述

1、创建测试表,

create table test_data_1(id number, value varchar2(20));

2、插入测试数据,插入1000条记录

insert into test_data_1 select level, 'val_'||level from dual connect by level <= 1000;

commit;

3、查询test_data_1表中全量数据记录数,select count(*) from test_data_1 t;可以发现共1000条记录;

4、编写语句,从test_data_1取id在21至30之间的记录,并创建新表test_data_2;

   create table test_data_2 as select * from test_data_1 where id between 21 and 30;

   

5、查询test_data_2表中全量数据记录数,select count(*) from test_data_2 t;可以发现共10条记录;

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-11-25
现有员工表A一张 ,要求抽取员工表中年纪小于25的数据单独存于B表
A表结构:
id、name、age

sql语法:
create table B as select id,name,age from A where age<25

不知是不是你要的效果本回答被提问者采纳
第2个回答  2015-06-26
现有员工表A一张 ,要求抽取员工表中年纪小于25的数据单独存于B表
A表结构:
id、name、age

sql语法:
create table B as select id,name,age from A where age<25

不知是不是你要的效果。
第3个回答  2012-02-23
从旧表中查出部分数据的语句如果假设为:
select * from 旧表 where 旧表数据的过滤条件

那创建新表的语句就是:
create table 新表 as select * from 旧表 where 旧表数据的过滤条件
第4个回答  2012-02-23
select * from A where 条件 into B; A是已经存在的表,B为需要创建的表,只能创建一次
相似回答