oracle利用现有表创建新表

上一篇 / 下一篇  2011-09-20 14:10:26 / 个人分类:数据库相关

CREATE TABLE <newtable> AS SELECT {* | column(s)} FROM <oldtable> [WHERE <condition>];
exp:
    SQL> CREATE TABLE yonghu_bak AS SELECT * FROM yonghul;
    SQL> CREATE TABLE yonghu_bak AS SELECT id, name,sex FROM yonghu;
    SQL> CREATE TABLE yonghu_bak AS SELECT * FROM yonghu WHERE 1=2;

当遇到一个部门有多个员工记录,需要去取出每个部门薪水最少的那笔时,就可以用到分析函数row_number()
select * from(

        select manager_id,employee_id,first_name,salary,row_number()
        over(partition by manager_id order by salary) as currowid
       from hr.employees)
where currowid = 1

PS:

(1)建一个新表,架构、字段属性、约束条件、数据记录跟旧表完全一样:

Create Table print_his_0013 as Select * from print_his_0007

(2)建一个新表,架构跟旧表完全一样,但没有内容:

Create Table print_his_0013 as Select * from print_his_0007 where 1=2

google_protectAndRun("render_ads.js::google_render_ad", google_handleError, google_render_ad);

TAG:

 

评分:0

我来说两句

Open Toolbar